Install PIP for older versions of Python on Linux, Mac, or Windows.

Python is a powerful and popular programming language, with a wealth of packages available for general programming, data science, and more. However, these packages usually do not ship automatically with Python installation, and instead need to be downloaded, installed, and managed by users themselves. All of these packages (including libraries and frameworks) are stored in a central repository called PyPI (the Python Package Index), PIP (the Preferred Installer Program) is the tool that manages this central repository.

After PIP is installed, it becomes easy to manage PyPI’s packages. Most packages can be installed by running python -m PIP install < package name > on a terminal or command-line interface.

Newer versions of Python 3 (3.4 or above) and Python 2 (2.7.9 or above) have PIP preinstalled. Older versions of Python do not ship PIP, but can be installed separately.

In this article, I’ll walk you through the process of installing PIP on Linux, Mac, and Windows systems. For more details, refer to the documentation for pip.pypa.

First, you need to install Python

You need Python installed on your system first, otherwise the PIP installer won’t understand any of the commands. You can run python commands on the cli, Bash, or terminal to check whether Python is installed in the system. If the system cannot recognize the Python command, download Python and install it. After the installation is complete, you should see some prompts to guide you to install PIP.

Install PIP on Linux

The commands for installing PIP vary from distribution to distribution of Linux.

On Fedora, RHEL, or CentOS, run the following command:

$ sudo dnf install python3
Copy the code

On Debian or Ubuntu, use apt package management tool to install:

$ sudo apt install python3-pip
Copy the code

Other distributions may also have different package management tools, such as Arch Linux which uses Pacman:

$ sudo pacman -S python-pip
Copy the code

Verify that PIP is installed correctly by executing the PIP –version command.

Installing PIP on a Linux system is as simple as that, and you can skip to the “Using PIP” section to continue reading.

Install PIP on your Mac

Python has been pre-installed on MacOS, but Python versions are generally older. If you are using Python, it is recommended to install Python 3 as an additional installation.

Python 3 can be installed on a Mac using Homebrew:

$ brew update && brew upgrade python
Copy the code

If you install the new version of Python 3 mentioned above, it comes with the PIP tool. You can verify this using the following command:

$ python3 -m pip --version
Copy the code

If you’re on a Mac and the installation process ends here, read on in the “Using PIP” section.

Install PIP on Windows

The following PIP installation procedure is for Windows 8 and Windows 10. The screenshots in the article below are from a Windows 10 environment, but are also available for Windows 8.

First verify that Python is installed.

If you want to use package management tools on Windows like Linux, Chocolatey is a good choice to make Python calls and updates easier. Chocolatey runs in PowerShell and Python can be installed with a simple command.

PS> choco install python
Copy the code

You can then install the required packages using PIP.

The use of PIP

PIP is used the same way on Linux, BSD, Windows, and Mac.

For example, installing a library:

python3 -m pip install foo --user
Copy the code

Unmount an installed library:

python3 -m pip uninstall foo
Copy the code

Find packages by name:

python3 -m pip search foo
Copy the code

Update PIP to a new version:

$ sudo pip install --upgrade pip
Copy the code

Note that the sudo command is not required in Windows because Windows manages user permissions in a unique way by creating an execution policy exception.

python -m pip install --upgrade pip
Copy the code

I hope you found this article helpful and feel free to share your experiences in the comments section.


Via: opensource.com/article/20/…

By Vijay Singh Khatri, lujun9972

This article is originally compiled by LCTT and released in Linux China