Pip is a package manager for Python and it is widely used to install python packages. Pip can be used to install packages from the Python Package Index. Let’s first understand modules and packages in python, and then we will jump into pip.
In Python, a module is a basic python file with the.py extension that contains collections of functions and global variables.
A Python package is a simple directory that contains groups of modules. Packages contains Python modules and a __init__.py file.
The Python standard library provides packages to perform various functions and pip can be used to install packages that are not a part of the Python standard library.
You can use pip from the command line by typing
pip followed by a command, such as
install to install a package or
uninstall to remove a package. For example, to install the popular NumPy package, you can type
pip install numpy in the command prompt.
Installing pip on Linux
To install Pip on Linux use following command on terminal:
sudo apt-get install python3-pip python-dev
Pip is included with Python versions 3.4 and above, so it is usually already available on your system if you have Python installed.
Checking which version of pip you are using
To check the version of pip, use the following command:
pip - -version
Installing packages using pip
To install packages using Python use the following command:
pip install package_name
Installing packages from GitHub
Python packages can be installed directly from GitHub. Use the git+https scheme that points to the downloadable GitHub package on Linux and Mac machines.
python3 -m pip install git+https://github.com/BillMills/python-package-example
Installing packages from requirements.txt file
Let’s first prepare a requirements.txt file and add required packages into it.
Now use the following command to install all the packages mentioned in the requirements.txt file.
pip install -r requirements.txt
Other helpful pip commands
You can upgrade pip to install the latest version. Use the following command to install the latest version:
python3 -m pip install --upgrade pip
To upgrade an already installed package use:
pip install --upgrade package-name
To list all the installed packages using pip use command:
Packages can be uninstalled using pip. To uninstall a package use the following command:
pip uninstall package_name
Using Packagecloud with pip
You can use Packagecloud to manage all of your packages if you want to manage Python packages on Pip. You can manage all kinds of packages in addition to Python packages, as well. Packagecloud provides a secure way to publish your packages on pip. Without owning any infrastructure, you can distribute and store different software packages using Packagecloud. Packagecloud enables both on-premises and cloud package management.