How to Install Python PIP on Windows, Mac, and Linux

Just like any programming language, Python supports third-party libraries and frameworks that you can install to avoid reinventing the wheel with every new project. If you want to use them, you can find these Python libraries on a central repository called the Python Package Index (PyPI).

It can be a frustrating and time-consuming process to download, install, and manage these packages manually. This is why many developers rely on a tool called PIP for Python to make the entire procedure simple and error-free. We’ll show you how to install PIP for Python in Windows, Mac, and Linux.

What Is PIP for Python?

PIP is an acronym that stands for “PIP Installs Packages” or “Preferred Installer Program.” It’s a package manager for Python that lets you manage PyPI packages not included with the standard Python distribution. PyPI hosts an extensive collection of frameworks, tools, and libraries for applications in finance, health, education, customer service, and more.

Is PIP Installed With Python?

If you’re using Python 2.7.9 (or greater), 3.4 (or greater), then PIP is already built into the Python installer. While beginners will download the latest release from the Python website, you should remember that a particular release isn’t supported indefinitely, nor can libraries support it.

As per the reports on the development release cycle, support for Python 3.4 already ended in March 2019, which means that it has bypassed the end-of-life branch, and you’ll no longer get security fixes. So you’ll end up dealing with more significant changes in both Python and in libraries at the same time, which makes upgrading scary.

Is Python Correctly Installed?

You have to make sure Python is properly installed on your system. There are different ways to install Python: through a package manager or from the official website. While the installation is simple, beginner users may not be aware of the best practices for managing Python or make mistakes that can later cause problems.

Installing and Managing Python PIP for Windows

By default, the Python installer places its executables in the user’s AppData directory, so that it doesn’t need administrative permissions. Or, you can specify a higher-level target directory (C:\Python3.9) to make it easier to find. The installation directory will get added to the system PATH, so you don’t have to configure anything.

If you’re using Chocolatey to install software packages, make sure to avoid mixing Chocolatey installation with a regular package on the same machine. To check the version of the installed Python, press Win + X and open Command Prompt.

Then, type in:

py --version

To check the PIP version, type in:

py -m pip --version

While PIP doesn’t get updated often, it’s still important to stay on top of new versions for reasons like bugs, security fixes, and compatibility. To check for any upgrades, type in:

py -m pip install --upgrade pip

If you get a “Python is not defined” message, then something has gone wrong during the installation process.

Installing and Managing Python PIP for Mac

On manual installation, a Python folder is created in the Applications folder and its framework in “/Library/Frameworks/Python.framework” which includes the Python executable and libraries. The installer adds this location to your shell path “usr/local/bin.” If you’re a beginner who only uses Python every so often, then this setup works well.

If you’re working on multiple Python projects, some at work or for other side-projects, the location itself (needs sudo privileges) creates hurdles. We’ll use Homebrew for installing software packages but not for Python development. The problem with using Homebrew Python is that it’s not in your control.

It can upgrade your Python, say 3.8 to 3.9, without your intervention. It can happen when other Homebrew-based packages (e.g., youtube-dl) use Python as its dependency gets updated. You lose control over “site-packages” and all the PIP packages that you had installed might become inaccessible.

The Homebrew Python documentation knows about this problem and recommends pyenv to manage Python environments. To make pyenv work, we’ll first install build dependencies through Homebrew. Open Terminal, then type in:

brew install openssl readline sqlite3 xz zlib

We’ll install pyenv

brew install pyenv

At last, we’ll need to update the shell profile configuration, i.e, ~/ .zshrc if your default shell is ZSH. Add the following lines:

echo 'eval "$(pyenv init --path)"' >> ~/.zprofile

Quit Terminal and restart again.

edit zshrc file mac

If you want to see all the versions of Python that pyenv can install for you, type in:

pyenv install --list

To install a specific Python version, type

pyenv install 3.9.7

It’ll take a bit of time for installation to get completed. Let’s assume that a project requires 3.8.12, a version that is not installed on the system. Let’s install this version through pyenv

pyenv install 3.8.12

You can see what versions of Python you have installed with

pyenv versions

“system” version is the one that comes with Mac, i.e., Python 2.7. Since it is deprecated, let’s forget about it. Now tell pyenv the default version you want to use.

pyenv-python-version-manager-mac

You can set Python versions at three levels: Global, Local, and Shell. Read the pyenv documentation for more details. Type in:

pyenv global 3.9.7

The global level sets the Python version for all shells and directories. We’ll check what happens when you check the current Python version.

python3 --version

To check the PIP version, type in:

python3 -m pip --version

And if you wish to check for any updates to PIP, type in:

python3 -m pip install --upgrade pip

The local level changes the Python version only for the current folders and subfolders. So if a project requires Python 3.8.12, type in:

pyenv local 3.812

That’s exactly what you want for a project. You want to use a different Python version in this folder without changing the global one.

Installing and Managing Python PIP for Linux

Many Linux distributions come packaged with Python, but it is possible that it may not be the latest version. To find out which Python version you have, open the Terminal and type in:

python --version

If you have Python installed on your machine, then one of these commands should respond with a version number. If you want to install the Python distribution on Linux, the built-in package manager is probably the best method.

Advanced Package Tool

sudo apt install python3-pip

Pacman Package Manager

sudo pacman -S python-pip

Dandified Yum

sudo dnf install python3-pip python3-wheel

Zypper Package Manager

sudo zypper install python3-pip python3-setuptools python3-wheel

Yum Package Manager

sudo yum install python3 python3-wheel

Install and Configure Virtual Environment

Once you have a base installation of a Python setup, don’t start installing packages directly into it with PIP. That’s because every project on your system will use “site-packages” to store and retrieve packages. At first glance, it may seem fine but imagine this situation. Let’s say you’re working on two projects: A and B, both of which have a dependency on the same library C.

You’ll start facing problems when you require a different version of library C. Maybe Project A requires version 1, but Project B needs version 2. Since Python can’t differentiate between versions in the “site-packages” you need to create isolated environments for Python projects.

Manage Python Packages With PIP

Once your PIP workflow is ready, you can start installing packages from PyPI.

Install

Mac: python3 -m pip install “SomeProject”

Windows: py -m pip install “SomeProject”

Install a Specific Version

Mac: python3 -m pip install “SomeProject=1.0”

Windows: py -m pip install “SomeProject=1.0”

Upgrade

Mac: python3 -m pip install –upgrade “SomeProject”

Windows: py -m pip install –upgrade “SomeProject”

Uninstall

Mac: python3 -m pip uninstall “SomeProject”

Windows: py -m pip uninstall “SomeProject”

List Installed Packages

Mac: python3 -m pip list

Windows: py -m pip list

List Outdated Packages

Mac: python3 -m pip list –outdated

Windows: py -m pip list –outdated

Learn More About Python

Python is indeed a useful programming language with applications ranging from web development to data analysis. Although we don’t focus much on installation, it’s important to set up Python correctly so that your learning process is smooth and error-free.

The best way to learn Python is by building projects. Read our guide on scraping a website with the beautiful soup Python library.

Releated

C vs. Python: The Key Differences

Many millions of programmers rely on the Python and C programming languages. They may have functional similarities, but they also have core differences. Notably, the C programming language is quite a bit older. It came out in 1972, while Python first appeared in 1991. Since its arrival, programmers have positively embraced C for its speed […]

How to Encrypt a Password in Python Using bcrypt

Password encryption masks users’ passwords so they become hard to guess or decode. It’s an essential step in developing secure user-base software. Whether you’re building one with Flask or another light Python Framework, you can’t ignore that step. That’s where bcrypt comes in. We’ll show you how to use bcrypt to hash your password in […]