17

i've installed debian 10.0.4 yesterday on my pc.

it had python version 3.7.3 installed on it , so i tried to update it to version 3.8.3 and now i have version 3.8.3 installed but when i try to install pip using the official get-pip.py it throws an exception . the details is :

Traceback (most recent call last):
  File "<frozen zipimport>", line 520, in _get_decompress_func
ModuleNotFoundError: No module named 'zlib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen zipimport>", line 520, in _get_decompress_func
ModuleNotFoundError: No module named 'zlib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen zipimport>", line 568, in _get_data
  File "<frozen zipimport>", line 523, in _get_decompress_func
zipimport.ZipImportError: can't decompress data; zlib not available

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "get-pip.py", line 23484, in <module>
    main()
  File "get-pip.py", line 198, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    from pip._internal.cli.main import main as pip_entry_point
  File "<frozen zipimport>", line 241, in load_module
  File "<frozen zipimport>", line 709, in _get_module_code
  File "<frozen zipimport>", line 570, in _get_data
zipimport.ZipImportError: can't decompress data; zlib not available

i must mention that the python (python2.7) and pip for python 2.7 is working , and i tried to reinstall python using source compilation and i got another error while installing it (zlib error)

2
  • How did you update python? In any case, a very important comment: never mix custom programs (and versions) with system one. Commented Jul 10, 2020 at 9:21
  • Pay attention to step 1 my answer below Commented Jul 10, 2020 at 9:31

1 Answer 1

35

Installing Python 3.8 on Debian 10

Building Python 3.8 on Debian is a relatively straightforward process and will only take a few minutes.

  1. Start by installing the packages necessary to build Python source:
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev liblzma-dev
  1. Download the latest release’s source code from the Python download page with wget or curl. At the time of writing this article, the latest release is 3.8.2:
curl -O https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
  1. When the download is complete, extract the tarball:
tar -xf Python-3.8.2.tar.xz
  1. Navigate to the Python source directory and run the configure script:
cd Python-3.8.2
./configure --enable-optimizations --enable-loadable-sqlite-extensions

The script performs a number of checks to make sure all of the dependencies on your system are present. The --enable-optimizations option will optimize the Python binary by running multiple tests, which will make the build process slower.

  1. Run make to start the build process:
make -j 4

Modify the -j to correspond to the number of cores in your processor. You can find the number by typing nproc.

  1. Once the build is done, install the Python binaries by running the following command as a user with sudo access:
sudo make altinstall

Do not use the standard make install as it will overwrite the default system python3 binary.

  1. At this point, Python 3.8 is installed on your Debian system and ready to be used. You can verify it by typing:
python3.8 --version
Python 3.8.2

source: https://linuxize.com/post/how-to-install-python-3-8-on-debian-10/

Sign up to request clarification or add additional context in comments.

7 Comments

It works fine up to this point then you get stuck, if you want to get further. For instance if you want to pip install mod_wsgi you need python3.8-dev which can be easily installed on every Ubuntu system using apt but with Debian you get an error "Unable to locate package python3.8-dev". Google cannot find neither a solution to the problem nor a definite answer that it doesn't working.
Try to add ./configure --enable-shared key while installing
Thank you for this response. I was able to compile, but when I started "python3.8 --version" I got this error: python3.8: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory I suppose it is the same problem with the missing python3.8-dev package.
I'm not a fan if some tutorial adds random switches (like that sqlite stuff) and just installs a bunch of dependencies without clearly explaining what they are for / why they are needed.
Installation was fine, but was getting warning after following Linuxize instructions, UserWarning: Could not import the lzma module. Your installed Python is incomplete. The instructions didn't include the library, liblzma-dev.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.