UserWarning: Could not import the lzma module. Your installed Python is incomplete

Solution 1:

If you compile Python from source, you must have the lzma-dev package installed, or it will not be built into python.

For ubuntu: sudo apt-get install liblzma-dev

For centos: yum install -y xz-devel

Then configure && make && make install

Solution 2:

I used other good answers from here and didn't solve the problem (Ubuntu 18.04, Python3.8), still get this warning. Actually there is one more package is needed to be installed to solve the problem:

sudo apt-get install lzma

So the whole pipeline (run in the python source code folder):

sudo apt-get install liblzma-dev
sudo apt-get install lzma
./configure --enable-optimizations
sudo make
sudo make altinstall

Solution 3:

On MacOS and pyenv (https://realpython.com/intro-to-pyenv/), I was able to have this warning go away by having xz installed with homebrew. Using version python 3.6.9 as an example

brew install xz && pyenv install 3.6.9

To use installed python, one needs to add this into .bash_profile

eval "$(pyenv init -)"

and start using it by running

pyenv global 3.6.9

Solution 4:

On macOS, if you manage your python with pyenv and package with homebrew, you need to install "xz" first:

brew install xz

After installing xz, you can install python 3.8 by (I'm using 3.8.2 as an example:

pyenv install 3.8.2

Above will fix the problem.