Skip to main content

Introduction to Python PIP

Python PIP

PIP (Pip Installs Packages) is the default package manager used to install, upgrade, and manage Python packages from the Python Package Index (PyPI).

It allows you to easily install third-party libraries and modules to extend the functionality of your Python environment.

Here's an overview of how to use PIP:

Installing PIP

PIP is typically installed by default with Python. However, if you have an older version of Python or a custom installation, you may need to install PIP separately.

You can check if PIP is installed by running the following command in your terminal or command prompt:

pip --version

If PIP is not installed, you can download the get-pip.py script from the official Python website and run it using Python to install PIP.

Installing Packages

Once you have PIP installed, you can use it to install packages from PyPI. To install a package, you can use the following command:

pip install package_name

Replace package_name with the name of the package you want to install. For example, to install the popular requests library, you would run:

pip install requests

PIP will download and install the specified package along with its dependencies.

Specifying Package Versions

You can specify a particular version of a package to install by appending the version number to the package name.

As an example:

pip install requests==2.26.0

This will install version 2.26.0 of the requests package. You can also use comparison operators like <, <=, >, >=, or the tilde (~) and caret (^) operators to specify version ranges.

Listing Installed Packages

To see a list of packages installed in your Python environment, you can use the following command:

pip list

This will display a list of installed packages along with their versions.

Updating Packages

You can use PIP to update packages to their latest versions. The following command will upgrade an installed package to the latest available version:

pip install --upgrade package_name

Replace package_name with the name of the package you want to update.

Uninstalling Packages

If you want to remove a package from your Python environment, you can use the following command:

pip uninstall package_name

Replace package_name with the name of the package you want to uninstall.

PIP provides many more features and options for managing Python packages, such as installing packages from local files, requirements files, or directly from version control systems.