Like any programming language, Python supports third-party libraries and frameworks. You can use these 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. Instead, many developers rely on a tool called PIP 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 a large collection of frameworks, tools, and libraries for applications in finance, health, 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. When you download the latest release, you should remember that a particular release isn’t supported indefinitely.

According to Python’s development cycle, support for Python 3.4 ended in March 2019. This 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 should make sure that Python is properly installed on your system. There are different ways to install Python: through a package manager or from the official Python website. While the installation is simple, it helps if you’re aware of the best practices for managing Python or it’s easy to make mistakes.

Install and Manage Python PIP for Windows

By default, the Python installer places its executables in your AppData directory, so it doesn’t need admin permissions. Or you can specify a higher-level target directory (C:\Python3.9) to make it easier to find.

The installation process optionally adds this directory to the system PATH, so you don’t have to configure anything. If you don’t do this during installation, you can add Python to the Windows PATH variable later, manually.

If you’re using Chocolatey to install packages, make sure to avoid mixing that 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:

        py -m pip --version
    

While PIP doesn’t update often, it’s still important to stay on top of new versions for bug fixes, 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.

Install and Manage Python PIP for Mac

On manual installation, Python creates a folder in /Applications and installs its framework in /Library/Frameworks/Python.framework. This includes the Python executable and its libraries. The installer adds a symlink to this location under /usr/local/bin. If you only use Python occasionally, this setup works well.

python framework executable libraries mac

Homebrew for Python Development

If you’re working on multiple Python projects, the default location, which needs sudo privileges, creates hurdles. Many people prefer to use Homebrew to install software packages, but should you use it for Python development? The problem with using Homebrew Python is that it’s not in your control.

Homebrew might upgrade your Python—e.g. 3.8 to 3.9—without your intervention. For example, the "youtube-dl" package uses Python as its dependency, the Python package may get updated as and when needed. You lose control over “site-packages” and all the PIP packages that you had installed might become inaccessible.

Use Pyenv to Manage Python Installation

The Homebrew Python documentation recommends pyenv to manage Python environments. To make pyenv work, install build dependencies through Homebrew. Open Terminal, then type in:

        brew install openssl readline sqlite3 xz zlib
    

Next, install pyenv:

        brew install pyenv
    

Finally, update the shell profile configuration, i.e ~/.zshrc if your default shell is ZSH. Add the following lines:

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

Quit Terminal and restart.

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. To set it globally, type:

        pyenv global 3.9.7
    

The global level sets the Python version for all shells and directories. 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:

        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
    

This command configures a specific Python version in the local folder without changing the global one.

Install and Manage Python PIP for Linux

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

        python3 --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 for Ubuntu or Debian-based Distributions

        sudo apt install python3-pip
    

Pacman Package Manager for Arch Linux

        sudo pacman -S python-pip
    

Dandified Yum for Fedora-based Distributions

        sudo dnf install python3-pip python3-wheel
    

Zypper Package Manager for openSUSE

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

Yum Package Manager for CentOS and Red Hat Enterprise Linux

        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 a central site-packages directory to store and retrieve packages. This may often be what you want, but if you have two projects requiring different libraries, it can be a problem.

Since Python stores only one global version of a library, you should create isolated environments for your 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 a useful language with applications ranging from web development to data analysis. It’s important to set up Python correctly so that your programming 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.