pip
PIP - Package Installer for Python
Section titled “PIP - Package Installer for Python”PIP is the Package Installer for Python. It is used to install packages from Python Package Index (PyPI) and other indexes. PIPPython Package Index
PyPI - Python Package Index
Section titled “PyPI - Python Package Index”PyPI is the default repository of Python packages for Python community that includes frameworks, tools and, libraries. Python developers can install and use packages in the Python application. It is open to all Python developers to consume and distribute their distributions. Developers can search or browse projects from pypi.org. PyPI
Install pip
Section titled “Install pip”PIP has been included with Python installer since Python 3.4. You can verify whether the pip is installed on your machine by running the following command in your console:
If you are using an older version of pip, you can upgrade pip by running the following command on Windows:
Execute the following command on Linux or Mac OS to upgrade pip:
If pip isn’t already installed, then first try to bootstrap it from the standard library by executing the following command in your console or terminal window:
If that still doesn’t install pip, the following steps should install pip on your platform.
- Download get-pip.py from https://bootstrap.pypa.io/get-pip.py and save it to your local folder.
get-pip.pyhttps://bootstrap.pypa.io/get-pip.py1. Navigate command prompt or terminal to the folder where you have downloaded the file and run the command: python get-pip.pypython get-pip.pyThis command will install pip in your pc. Additionally, it also installs the wheel and setuptools. wheelsetuptools
pip Help command
Section titled “pip Help command”The pip help command is used to get a list of all the functions available in pip.
pip help
Installing packages
Section titled “Installing packages”PyPI maintains packages as projects. Use the following pip command to install the latest version of the project.
Pip install "project-name"Pip install "project-name"
Use the following command installs the specific version of the project:
pip install "project-name==2.4"pip install "project-name==2.4"
Use the following command to install a version that’s “compatible” with a certain version:
pip install "project-name~=2.4"pip install "project-name~=2.4"
Let’s install a package to send an HTTP request in Python. urllib3 is a powerful, user-friendly HTTP client for Python. Before using urllib3 package in your application, install it using the pip command, as shown below.
pip
The above command will install the latest version of urllib3. Now, you can import and use it, as shown below.
urllib3
import urllib3 http = urllib3.PoolManager() req = http.request('GET', 'http://www.google.com') print(req.status)import urllib3 http = urllib3.PoolManager() req = http.request('GET', 'http://www.google.com') print(req.status)
List packages
Section titled “List packages”The list command can be used to see all the packages that have been installed on the system. If you want to check all the packages, use the pip list command:
pip list
This will list all the packages available to use in your system. Notice that urllib3 package is also listed there.
urllib3
Show package
Section titled “Show package”If you want to check the metadata of a package, then use pip show command. The following command will display the metadata of the urllib3 package. [email protected]
Uninstalling a Package
Section titled “Uninstalling a Package”The pip uninstall command can be used to remove a package. For example, if you want to remove urllib3 package, you can simply use the following command:
pip uninstall``urllib3
The pip package manager will ask you to confirm if you want to uninstall the package.Proceed (y/n)?:If you press y, the package will be removed.
Proceed (y/n)?:
Thus, you can use pip as a package manager of your Python application.