In this article, we will discuss what is PIP, and how to install, upgrade and uninstall packages using Python PIP. So before starting and using it, let us understand what is a Python PIP.
What is Python PIP?
Python PIP is the package manager for Python packages. We can use PIP to install packages that do not come with Python. The basic syntax of PIP commands in the command prompt is:
How to Install Python PIP?
Python PIP comes pre-installed on 3.4 or older versions of Python. To check whether PIP is installed or not type the below command in the terminal.
This command will tell the version of the Pip if it is already installed in the system.
Checking Python PIP version
If you do not have PIP installed on your system refer to the below articles.
How to Install Package with Python PIP
We can install additional packages by using the Python pip install command. Let’s suppose we want to install the Numpy using PIP. We can do it using the below command.
pip install numpy
Example 1: When the required package is not installed.
Using Python PIP to install a new package
Example 2: When the required package is already installed.
Using Python PIP to install an existing package
Specifying Package Version using Python PIP
We can also install the package of a specific version by using the below command.
pip install package_name==version
This will install the package with the specified version
Display Package information using Python PIP
We can use the Python pip show command to display the details of a particular package.
pip show numpy
Display package information using Python PIP
- Requires column shows the dependencies required by the NumPy package
- Required by shows the packages that require NumPy
Get a list of locally installed Python Modules using Python PIP
The Python pip list command displays a list of packages installed in the system.
Getting a list of locally installed modules using Python PIP
Uninstall Packages with Python PIP
The Python pip uninstall command uninstalls a particular existing package.
pip uninstall numpy
Uninstall package with Python PIP
Note: The PIP uninstall command does not uninstall the package dependencies. If you want to remove the dependencies as well then you can see the dependencies using the pip show command and remove each package manually.
Search Packages with Python PIP
We can search for a particular existing package using the Python pip search command.
pip search numpy
Search package with Python PIP
Using Requirement files with Python PIP
Let’s suppose you want more than one package then instead of installing each package manually, you can install all the modules in a single go. This can be done by creating a requirements.txt file. Let’s suppose the requirements.txt file looks like this:
pip install -r requirements.txt
Using requirements file to install packages with Python PIP
Listing additional Packages with Python PIP
The Python pip freeze command is used to list packages that don’t come pre-installed with Python.
Listing additional packages with Python PIP
Listing Outdated Packages with Python PIP
Python pip list –outdated command is used to list all the packages that are outdated. This command cross-checks the installed package information with the PIP repository.
pip list --outdated
Listing outdated packages with Python PIP
Upgrading Packages with Python PIP
Python pip install –user –upgrade is used to update a package.
pip install --user --upgrade package_name
Upgrading packages with Python PIP
Upgrading packages with Python PIP
We can also upgrade any package to a specific version using the below command.
pip install --user --upgrade package_name==version
Downgrading Packages with Python PIP
the Python pip install –user command is used to downgrade a package to a specific version.
pip install --user package_name==version
Downgrading packages with Python PIP
FAQ on Python PIP
Q: What is PIP?
A: PIP stands for “PIP Installs Packages.” It is the package installer for Python, used to download and manage Python packages from the Python Package Index (PyPI) or other package repositories.
Q: How do I install PIP?
A: PIP is usually installed by default when you install Python. If you have a recent version of Python, you should already have PIP installed. You can check its installation by running pip –version in your command prompt or terminal. If PIP is not installed, you can download the get-pip.py script from the official website and run it to install PIP.
Q: How do I use PIP to install Python packages?
A: To install a package using PIP, you can use the following command: pip install package_name. Replace package_name with the name of the package you want to install. PIP will automatically download and install the latest version of the package from PyPI.
Q: How do I upgrade a package with PIP?
A: You can upgrade a package to the latest version using the command: pip install –upgrade package_name. PIP will check for a newer version of the package and install it if available.