📜  python 3.7 centos in _run_pip import pip._internal zipimport.ZipImportError: can't decompress data; zlib 不可用 make: *** [altinstall] 错误 1 - Python (1)

📅  最后修改于: 2023-12-03 15:33:57.904000             🧑  作者: Mango

Python 3.7 on CentOS - Installation Error

If you're a Python developer using CentOS, you may encounter issues when trying to install Python 3.7. An error message similar to the following might appear:

_run_pip import pip._internal zipimport.ZipImportError: can't decompress data; zlib not available make: *** [altinstall] Error 1

This error is typically caused by a missing dependency, in this case zlib, which is required for Python's compression and decompression functions. The good news is that this problem can be easily resolved with a few simple steps.

Solution

To fix this issue, you will need to install the zlib development package and rebuild Python from source:

  1. Open a terminal and run the following command to install the zlib development package:

    sudo yum install zlib-devel
    
  2. Download the source code for Python 3.7 from the official website:

    wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
    
  3. Extract the downloaded archive and navigate to the extracted directory:

    tar xvf Python-3.7.0.tgz
    cd Python-3.7.0
    
  4. Configure the installation with the following command:

    ./configure --prefix=/usr/local --enable-shared --with-zlib=/usr/include
    

    Note: If you installed the zlib development package in a different location, replace /usr/include with the appropriate path.

  5. Compile and install Python with the following commands:

    make
    sudo make altinstall
    

    Note: The altinstall command ensures that the new Python version is installed alongside the system version, rather than overwriting it.

  6. Verify that Python 3.7 is installed and working correctly by running the following command:

    python3.7 -V
    

    This should display the version number for Python 3.7.

Congratulations, you have successfully installed Python 3.7 on CentOS and resolved the zlib dependency error! This should enable you to proceed with your Python development tasks without any further issues.