Skip to main content

Whilst installing Python 3.11.6 and running the command 'sudo make altinstall', the following error

Creating directory /usr/local/share/man/man1
/usr/bin/install -c -m 644 ./Misc/python.man \
    /usr/local/share/man/man1/python3.11.1
if test "xupgrade" != "xno"  ; then \
    case upgrade in \
        upgrade) ensurepip="--altinstall --upgrade" ;; \
        install|*) ensurepip="--altinstall" ;; \
    esac; \
     ./python -E -m ensurepip \
        $ensurepip --root=/ ; \
fi
Traceback (most recent call last):
 File "<frozen zipimport>", line 576, 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 624, in _get_data
 File "<frozen zipimport>", line 579, 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 "<string>", line 6, in <module>
 File "<frozen runpy>", line 222, in run_module
 File "<frozen runpy>", line 148, in _get_module_details
 File "<frozen runpy>", line 112, in _get_module_details
 File "<frozen zipimport>", line 195, in get_code
 File "<frozen zipimport>", line 758, in _get_module_code
 File "<frozen zipimport>", line 626, in _get_data
zipimport.ZipImportError: can't decompress data; zlib not available
Traceback (most recent call last):
 File "<frozen runpy>", line 198, in _run_module_as_main
 File "<frozen runpy>", line 88, in _run_code
 File "/usr/src/Python-3.11.6/Lib/ensurepip/__main__.py", line 5, in <module>
   sys.exit(ensurepip._main())
            ^^^^^^^^^^^^^^^^^
 File "/usr/src/Python-3.11.6/Lib/ensurepip/__init__.py", line 286, in _main
   return _bootstrap(
          ^^^^^^^^^^^
 File "/usr/src/Python-3.11.6/Lib/ensurepip/__init__.py", line 202, in _bootstrap
   return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/usr/src/Python-3.11.6/Lib/ensurepip/__init__.py", line 103, in _run_pip
   return subprocess.run(cmd, check=True).returncode
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/usr/src/Python-3.11.6/Lib/subprocess.py", line 571, in run
   raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/src/Python-3.11.6/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmpjl89gbf3/setuptools-65.5.0-py3-none-any.whl\', \'/tmp/tmpjl89gbf3/pip-23.2.1-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmpjl89gbf3\', \'--root\', \'/\', \'--upgrade\', \'setuptools\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
make: *** [Makefile:1878: altinstall] Error 1

 

Working the zlib zipimport.ZipImportError error

zlib

zipimport.ZipImportError: can't decompress data; zlib not available

The error message "zipimport.ZipImportError: can't decompress data; zlib not available" indicates that the Python interpreter is encountering an issue related to zlib, a library used for data compression. This error can occur when Python is trying to import or load a module from a compressed .zip archive, but the zlib library required for decompression is not available or accessible.

Steps to resolve this issue

Begin by checking if the zlib library is installed on an Ubuntu system, you can use the apt package manager.   Use the apt list command followed by the library name to check if it is installed. For example, to check if the zlib1g-dev library is installed:

apt list --installed | grep zlib1g-dev

This command will display a list of installed packages that match the specified library. If it's installed, you will see the package name and version. If it's not installed, you won't see any output.  

If you want to check if a library is available for installation via the package manager (i.e., if it's not currently installed), you can use the apt search command. For example

apt search zlib1g-dev

Response

r-bioc-zlibbioc/focal 1.32.0+dfsg-1 all
  (Virtual) zlibbioc Bioconductor package

zlib1g-dev/focal-updates,focal-security 1:1.2.11.dfsg-2ubuntu1.5 amd64
  compression library - development

 

Install or Reinstall zlib

On many Linux systems, zlib is a separate library, and it might not be installed by default. You can install zlib by using your system's package manager. For example, on Ubuntu, you can run

sudo apt-get install zlib1g-dev

If zlib is already installed, consider reinstalling it in case it is corrupted.

 

Rebuild Python

If you're running a custom or non-system Python installation, it's possible that zlib support was not included when Python was built. You may need to rebuild Python with zlib support.

 

Check Python Version

Ensure that you are using a version of Python for which zlib is supported. Older Python versions might not have full zlib support, so consider upgrading to a more recent version.  I'm currently running Python 3.11.6, therefore not an issue.

 

Environment Variables

Make sure that the environment variables, such as LD_LIBRARY_PATH or PYTHONPATH, are correctly set to include the directories where zlib libraries are located.

Checking LD_LIBRARY_PATH

LD_LIBRARY_PATH is an environment variable that specifies a list of directories where the system should look for shared libraries before searching the standard locations. To check if it's correctly set, you can open a terminal and run:

echo $LD_LIBRARY_PATH

This command will display the value of the LD_LIBRARY_PATH variable. If it's empty, no additional directories are included. If it's set, you'll see a list of directories separated by colons (":"). Ensure that the directories containing the required libraries, such as zlib, are included in this list.

Checking PYTHONPATH

PYTHONPATH is an environment variable that specifies a list of directories where Python should look for modules and packages. To check if it's correctly set, you can open a terminal and run:

echo $PYTHONPATH

This command will display the value of the PYTHONPATH variable. If it's empty, no additional directories are included. If it's set, you'll see a list of directories separated by colons (":"). Ensure that the directories containing the Python modules you need are included in this list.

If these environment variables are not set or do not include the necessary directories, you can modify them as needed. You can set these variables in your shell's configuration files, such as .bashrc or .bash_profile for the LD_LIBRARY_PATH, or you can set them for Python using the sys.path list in your Python scripts or through environment variables.

Not installed?

You can set system-wide environment variables by modifying shell configuration files, such as .bashrc, .bash_profile, or /etc/environment, depending on the shell and scope you want. Such as, to set LD_LIBRARY_PATH for the entire system, you can add the following line to /etc/environment:

LD_LIBRARY_PATH="/path/to/your/zlib/library:$LD_LIBRARY_PATH"

Make sure to replace /path/to/your/zlib/library with the actual path to your zlib library.  After making changes to system-wide environment variables, you may need to restart the system or re-login for the changes to take effect.

 

How to find the zlib path

To find the path to the zlib library on an Ubuntu system, you can use various methods, such as searching for the library file or checking the system's library paths. Here are some steps you can follow to find the path to zlib:

Option 1: Using the whereis Command

The whereis command can help you find the location of system libraries, including zlib. Open a terminal and run

whereis zlib

This command will display the path to the zlib library, which is typically located in a system library directory, such as /lib or /usr/lib.

Response

zlib: /usr/include/zlib.h /usr/share/man/man3/zlib.3.gz

 

Option 2: Using the dpkg Command

You can use the dpkg command to find information about the zlib package, which includes the location of the library files. Run:

dpkg -L zlib1g

This command will list the files and directories associated with the zlib package, including the path to the zlib library.

/.
/lib
/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu/libz.so.1.2.11
/usr
/usr/share
/usr/share/doc
/usr/share/doc/zlib1g
/usr/share/doc/zlib1g/changelog.Debian.gz
/usr/share/doc/zlib1g/copyright
/lib/x86_64-linux-gnu/libz.so.1

 

Option 3: Using the find Command

You can use the find command to search the entire filesystem for the zlib library file. Run:

sudo find / -name "libz.so.*"

This command will search for files named libz.so.*, which is the naming pattern for zlib library files. It may take some time to search the entire filesystem.

Response

/snap/snapd/20290/lib/x86_64-linux-gnu/libz.so.1
/snap/snapd/20290/lib/x86_64-linux-gnu/libz.so.1.2.8
/snap/snapd/20092/lib/x86_64-linux-gnu/libz.so.1
/snap/snapd/20092/lib/x86_64-linux-gnu/libz.so.1.2.8
/snap/core18/2790/lib/x86_64-linux-gnu/libz.so.1
/snap/core18/2790/lib/x86_64-linux-gnu/libz.so.1.2.11
/snap/core18/2785/lib/x86_64-linux-gnu/libz.so.1
/snap/core18/2785/lib/x86_64-linux-gnu/libz.so.1.2.11
/snap/core20/2015/usr/lib/x86_64-linux-gnu/libz.so.1
/snap/core20/2015/usr/lib/x86_64-linux-gnu/libz.so.1.2.11
/snap/core20/1974/usr/lib/x86_64-linux-gnu/libz.so.1
/snap/core20/1974/usr/lib/x86_64-linux-gnu/libz.so.1.2.11
/usr/lib/x86_64-linux-gnu/libz.so.1
/usr/lib/x86_64-linux-gnu/libz.so.1.2.11

 

Option 4: Check Common Library Paths

Zlib libraries are often located in standard library paths. You can check the common library paths using the ldconfig command:

ldconfig -p | grep libz

This command will display a list of libraries that include "libz" in their names, along with their paths.

Response

	libzstd.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libzstd.so.1
	libzip.so.4 (libc6,x86-64) => /lib/x86_64-linux-gnu/libzip.so.4
	libz.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libz.so.1

 

Option 5: Check the /usr/lib Directory

The zlib library is often located in the /usr/lib directory. You can check this directory to see if the zlib library is present:

ls /usr/lib | grep libz

This command will list files in the /usr/lib directory that contain "libz" in their names.

 

Check Python Installation

If you have multiple Python installations on your system, make sure you are using the correct one. You can check the Python version and its path using the following commands

which python
python --version

 

 

 

Related articles

Andrew Fletcher06 May 2024
Exploring historical memory usage monitoring with Sysstat
In the realm of system administration and monitoring, understanding memory usage trends is crucial for maintaining system health and performance. While tools like htop offer real-time insights into memory usage, they lack the capability to provide historical data. So, what if you need to analyze...
Andrew Fletcher01 May 2024
Common commands used in Ubuntu - in progress
A growing list of commands I've used and what they do in no specific ordersudo snap install bw ps aux | grep java whoami ip addr show uptime sudo apt update &amp;&amp; sudo apt upgrade -y cat /etc/os-release sudo apt-get install needrestart sudo reboot sudo needrestart sudo ckan sysadmin...