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

Downloading, installing, and managing these packages by hand are often frustrating and time-consuming. this is often why many Python developers believe a special tool called PIP for Python (or Python PIP) to form everything much easier and faster.

What Is PIP for Python?

PIP is an acronym that stands for “PIP Installs Packages” or “Preferred Installer Program”. It’s a command-line utility that permits you to put in , reinstall, or uninstall PyPI packages with an easy and easy command: pip.

If you’ve ever done any command-line work on Windows (with the Command Prompt) or Mac or Linux (with the Terminal and Bash), then you’ll skip right down to the installation instructions for your particular OS .

 Is PIP Installed With Python?

If you’re using Python 2.7.9 (or greater) or Python 3.4 (or greater), then PIP comes installed with Python by default. If you’re using an older version of Python, you’ll got to use the installation steps below. Otherwise, skip to rock bottom to find out the way to start using PIP.

If you’re running Python during a virtual environment created with either virtualenv or pyvenv, then PIP are going to be available no matter the Python version.

Is Python Correctly Installed?

You have to form sure Python is correctly installed on your system. On Windows, open up the prompt using Windows key + X and selecting prompt . On Mac, open the Terminal using Command + Space and checking out terminal. On Linux, open the Terminal using Ctrl + Alt + T. Linux shortcuts may vary by distribution.

Then type:

[pastacode lang=”bash” manual=”python%20–version” message=”” highlight=”” provider=”manual”/]

On Linux, Python 3.x users may need to use:

[pastacode lang=”bash” manual=”python3%20–version” message=”” highlight=”” provider=”manual”/]

If you get a version number (e.g. “Python 2.7.5”) then Python is prepared to travel .

If you get a “Python isn’t defined” message, then you’ll need to first install Python properly. That’s beyond the scope of this text . The Python site has some detailed instructions for installation.

How to Install PIP on Windows

These instructions should work on Windows 7, Windows 8.1, and Windows 10:

Download the get-pip.py installer script. If you’re on Python 3.2, you’ll need this version of get-pip.py instead. Either way, right-click on the link and choose Save As… and reserve it to any safe location, like your Downloads folder.

Open the prompt and navigate to the get-pip.py file.

Run the subsequent command: python get-pip.py

How to Install PIP on Mac

Modern Mac systems accompany Python and PIP already installed. However, this version of Python tends to be outdated and not the simplest choice for serious Python development. It’s highly recommended that you simply install a more current version of Python and PIP.

If you would like to use the native system Python installation but don’t have PIP available, you’ll install PIP with the subsequent command in Terminal:

[pastacode lang=”bash” manual=”sudo%20easy_install%20pip” message=”” highlight=”” provider=”manual”/]

How to Install PIP on Linux

If your Linux distribution came with Python already installed, you should be able to install PIP using your system’s package manager. This is preferable since system-installed versions of Python do not play nicely with the get-pip.py script used on Windows and Mac.

Advanced Package Tool (Python 2.x)

[pastacode lang=”bash” manual=”sudo%20apt-get%20install%20python-pip” message=”” highlight=”” provider=”manual”/]

Advanced Package Tool (Python 3.x)

[pastacode lang=”bash” manual=”sudo%20apt-get%20install%20python3-pip” message=”” highlight=”” provider=”manual”/]

pacman Package Manager (Python 2.x)

[pastacode lang=”bash” manual=”sudo%20pacman%20-S%20python2-pip” message=”” highlight=”” provider=”manual”/]

pacman Package Manager (Python 3.x)

[pastacode lang=”bash” manual=”sudo%20pacman%20-S%20python-pip” message=”” highlight=”” provider=”manual”/]

 

Yum Package Manager (Python 2.x)

[pastacode lang=”bash” manual=”sudo%20yum%20upgrade%20python-setuptools%20sudo%20yum%20install%20python-pip%20python-wheel” message=”” highlight=”” provider=”manual”/]

Yum Package Manager (Python 3.x)

[pastacode lang=”bash” manual=”sudo%20yum%20install%20python3%20python3-wheel” message=”” highlight=”” provider=”manual”/]

Dandified Yum (Python 2.x)

[pastacode lang=”bash” manual=”sudo%20dnf%20upgrade%20python-setuptools%20sudo%20dnf%20install%20python-pip%20python-wheel” message=”” highlight=”” provider=”manual”/]

Dandified Yum (Python 3.x)

[pastacode lang=”bash” manual=”sudo%20dnf%20install%20python3%20python3-wheel” message=”” highlight=”” provider=”manual”/]

Zypper Package Manager (Python 2.x)

[pastacode lang=”bash” manual=”sudo%20zypper%20install%20python-pip%20python-setuptools%20python-wheel” message=”” highlight=”” provider=”manual”/]

Zypper Package Manager (Python 3.x)

[pastacode lang=”bash” manual=”sudo%20zypper%20install%20python3-pip%20python3-setuptools%20python3-wheel” message=”” highlight=”” provider=”manual”/]

How to Install PIP on Raspberry Pi

As a Raspberry Pi user, you’re probably running Raspbian since it’s the official OS designated and provided by the Raspberry Pi Foundation. You’re liberal to install another OS , like Ubuntu. If that’s the case you ought to check out the Linux instructions.

Starting with Raspbian Jessie, PIP comes installed by default. It’s one among the large reasons to upgrade to Raspbian Jessie rather than sticking with Raspbian Wheezy or Raspbian Jessie Lite. However, if you’re on an older version of Raspbian, you’ll still install PIP.

On Python 2.x:

[pastacode lang=”bash” manual=”sudo%20apt-get%20install%20python-pip” message=”” highlight=”” provider=”manual”/]

On Python 3.x:

[pastacode lang=”bash” manual=”sudo%20apt-get%20install%20python3-pip” message=”” highlight=”” provider=”manual”/]

With Raspbian, Python 2.x users should use pip while Python 3.x users should use pip3 when issuing PIP commands.

How to Upgrade PIP for Python

While PIP itself doesn’t update fairly often , it’s still important to remain on top of latest versions because there could also be important fixes to bugs, compatibility, and security holes. Fortunately, upgrading PIP is quick and straightforward .

On Windows:

[pastacode lang=”bash” manual=”python%20-m%20pip%20install%20-U%20pip” message=”” highlight=”” provider=”manual”/]

On Mac, Linux, or Raspberry Pi:

[pastacode lang=”bash” manual=”pip%20install%20-U%20pip” message=”” highlight=”” provider=”manual”/]

How to Manage Python Packages With PIP

Once PIP is ready, you can start installing packages from PyPI:

[pastacode lang=”bash” manual=”pip%20install%20package-name” message=”” highlight=”” provider=”manual”/]

To install a specific version of a package instead of the latest version:

[pastacode lang=”bash” manual=”pip%20install%20package-name%3D%3D1.0.0″ message=”” highlight=”” provider=”manual”/]

To search PyPI for a particular package:

[pastacode lang=”bash” manual=”pip%20search%20%22query%22″ message=”” highlight=”” provider=”manual”/]

To see details about an installed package:

[pastacode lang=”bash” manual=”pip%20show%20package-name” message=”” highlight=”” provider=”manual”/]

To list all installed packages:

[pastacode lang=”bash” manual=”pip%20list” message=”” highlight=”” provider=”manual”/]

To list all outdated packages:

[pastacode lang=”bash” manual=”pip%20list%20–outdated” message=”” highlight=”” provider=”manual”/]

To upgrade an outdated package:

[pastacode lang=”bash” manual=”pip%20install%20package-name%20–upgrade” message=”” highlight=”” provider=”manual”/]

Note that older versions of a package are automatically removed by PIP when upgrading to a newer version of that package.

To completely reinstall a package:

[pastacode lang=”bash” manual=”pip%20install%20package-name%20–upgrade%20–force-reinstall” message=”” highlight=”” provider=”manual”/]

To completely get rid of a package:

[pastacode lang=”bash” manual=”pip%20uninstall%20package-name” message=”” highlight=”” provider=”manual”/]

 

Categorized in: