How To Install PIP For Python Package Management

Pip is not strange to python users, and it’s the first thing that comes to mind when you want to install a python module. Pip is a tool for installing and managing Python packages and is a replacement for easy_install. Today, let’s talk about how to install Pip.

1. Install PIP Use Script.

$ wget
$ [sudo] python

2. Install PIP Use Source Code.

$ curl -O
$ tar xvfz pip-X.X.tar.gz
$ cd pip-X.X
$ python install

3. Error Fix During Installation.

3.1 An error occurred while trying to run Make sure you have setuptools or distribute installed.

This error indicates that setuptools should be installed first. After installing setuptools, just install the source code again.

Install setuptools

wget -q

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

When instal pip use script, this error may occur in some environment. It seems that the zlib library is not installed. You should install zlib library first then run pip script to install it.

Install zlib library

$ sudo yum install zlib

When the installation is complete, errors will still be reported. Google Search found that zlib-dev needs to be installed also. So let’s install the zlib library again.

$ sudo yum install zlib*

The installation should be OK, and the result is disappointing, and the same error will still be reported. But clearly we have installed the zlib library, why do we still report errors?

After investigate found that python needs to be recompiled and reinstalled. You also need to modify the Modules/ setup.dist file in the installation source file before recompiling. Just remove the comment character of below lines in Modules/setup.dist file.

#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

Then compile and install again (execute the following command in Python’s installation source directory).

$ make && make install

After python reinstall successful, run below script to install pip again and success.

$ sudo python

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.