Install Python Package with PIP on Windows, Mac and Linux

Like many other programming languages, Python supports extremely useful third-party libraries and frameworks that you can use to avoid losing your rewrite from scratch.

Like many other programming languages, Python supports extremely useful third-party libraries and frameworks that you can use to avoid losing your rewrite from scratch. You can find these on a central repository called PyPI (Python Packages Index).

However, downloading, installing, and managing these packages can be annoying and time-consuming, which is why Python developers rely on a special tool called PIP for Python to help them all. Things are easier and faster.

What is PIP?

PIP is a library manager for Python , which stands for Preferred Installer Program . This is a command line utility that allows you to install, reinstall or uninstall PyPI packages with a simple and straightforward command line: pip.

If you are using Python2 from version 2.7.9 or Python 3 from 3.4, then PIP is installed by default on Python. For older versions, you'll need a few more steps that TipsMake.com will introduce below to install.

If you are running Python in a virtual environment created with virtualenv or pyvenv, then PIP is already available on all versions.

Has your Python been properly installed?

To use PIP, you must make sure your Python has been installed correctly on your device. To check, you do the following:

  1. With Windows operating system, open Command Prompt with Windows key + X and select Command Prompt.
  2. On the Mac, open Terminal with Command + Space and search for the terminal.
  3. On Linux, open Terminal with Ctrl + Alt + T.

Then type:

 python --version 

With Python 3.x on Linux, use the command:

 python3 --version 

If you get the version number (for example, " Python 2.7.5 "), then that means Python is ready to work.

If you get the message " Python is not defined ", then you must reinstall Python properly.

How to install PIP

(Skip if you are using Python 2.7.9 or Python 3.4 or higher)

1. On Windows

Version: Windows 7, Windows 8.1 and Windows 10.

  1. get-pip.py
  2. get-pip.py (for Python 3.2)

Step 1: Download the above script by right-clicking on the link, selecting Save As . (Save the link to .) to save the file to the folder you want.

Step 2: Open the Command Prompt and navigate to the file get-pip.py.

Step 3: Run the following command:

 python get-pip.py 

2. On Mac

Currently Python on Mac devices has PIP available. However, if you still want to use older versions, you can install PIP with the following command in Terminal:

 sudo easy_install pip 

If you want to use an 'up-to-date' version of Python, you can install more Homebrew - an application that helps you find, install, uninstall or update software and libraries included in Linux. , Unix is ​​not available in MacOSX.

If your Mac has installed Homebrew, install it in Python using the command:

 brew install python 

If the installation process is successful but PIP is not available, you need to re-link Python using the following Terminal command:

 brew unlink python && brew link python 

3. On Linux

If your Linux distribution is included with Python, you can install PIP using the system's package manager.

  1. Advanced Package Tool (Python 2.x)
 sudo apt-get install python-pip 
  1. Advanced Package tool (Python 3.x)
 sudo apt-get install python3-pip 
  1. pacman Package Manager (Python 2.x)
 sudo pacman -S python2-pip 
  1. pacman Package Manager (Python 3.x)
 sudo pacman -S python-pip 
  1. Yum Package Manager (Python 2.x)
 sudo yum upgrade python-setuptools 
sudo yum install python-pip python-wheel
  1. Yum Package Manager (Python 3.x)
 sudo yum install python3 python3-wheel 
  1. Dandified Yum (Python 2.x)
 sudo dnf upgrade python-setuptools 
sudo dnf install python-pip python-wheel
  1. Dandified Yum (Python 3.x)
 sudo dnf install python3 python3-wheel 
  1. Zypper Package Manager (Python 2.x)
 sudo zypper install python-pip python-setuptools python-wheel 
  1. Zypper Package Manager (Python 3.x)
 sudo zypper install python3-pip python3-setuptools python3-wheel 

4. On the Raspberry Pi

If you are a Raspberry Pi user, the most recommended operating system is Raspbian because it is the official operating system designed and powered by the Raspberry Pi Foundation.

Starting with Raspbian Jessie , if you are using Jessie, PIP is installed by default. This is definitely one of the important reasons for you to upgrade to Raspbian Jessie instead of sticking with Raspbian Wheezy or Raspbian Jessie Lite. However, if you are using an older version of Raspbian, you can still install PIP as follows:

  1. In Python 2.x:
 sudo apt-get install python-pip 
  1. In Python 3.x:
 sudo apt-get install python3-pip 

For Raspbian, Python 2.x users should use pip while Python 3.x users should use pip3 when running the PIP command.

How to upgrade PIP for Python

Although PIP does not update regularly, it is important that the app stays on top of the new versions because PIP can have bug fixes, compatibility issues and security holes. Fortunately, upgrading PIP is quick and simple.

  1. On Windows:
 python -m pip install -U pip 
  1. On Mac, Linux or Raspberry Pi:
 pip install -U pip 

On certain versions of Linux and Raspberry Pi, you need to use pip3 instead.

Managing Python Packages with PIP

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

 pip install package-name 

To install a specific version of the package:

 pip install package-name==1.0.0 

Search for a specific PyPI package:

 pip search "query" 

See details about an installed package:

 pip show package-name 

List all installed packages:

 pip list 

List all outdated packages:

 pip list --outdated 

Upgrade obsolete package:

 pip install package-name --upgrade 

Note : PIP will automatically delete older versions of packages when it has been upgraded to a newer version.

Completely reinstalling a package:

 pip install package-name --upgrade --force-reinstall 

Exit a package:

 pip uninstall package-name 

Python is very interesting. Quantrimang recommends that you learn more about Python to be motivated to continue learning and to push your skills to new heights. You can refer to some of the following articles:

  1. What is Python? Why choose Python?
  2. 6 reasons why Python will become the programming language of the future
  3. 11 tips for learning Python for 'newbie'
  4. Open source Python projects for beginners
  5. More than 100 Python exercises have solutions (sample code)
Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile