Getting a “NameError” while writing a long code or importing a module?
Don’t know how to solve it and proceed ahead?
Let’s get into this.
In This Article, You Will Learn About Python PIP.
Table of Contents
What is PIP?
PIP – PIP is a Python package installer. It is a package of dozens of code in a file (module) that is created for specific purpose to help the developer by importing it.
Install PIP
When you install Python from official website, PIP is already installed with it.
Note:
Usually, pip is automatically installed if you are:
-working in a virtual environment
-using Python downloaded from python.org
-using Python that has not been modified by a redistributor to remove ensurepip
You can install PIP, if it is not installed by default. Visit to official documentation to install PIP by using get-pip.py.
Download Python Script
Download the script, from https://bootstrap.pypa.io/get-pip.py.
Open the command prompt, cd to the folder containing the get-pip.py file and run:
Windows
py get-pip.py
MacOS
python get-pip.py
Linux
python get-pip.py
Or, it is much easier to install PIP while setting up new Python environment. Just visit Python official website python.org to install latest version of Python.
PIP2 and PIP3
PIP is mandatory package that should be installed in every version of Python whether it is Python 2 or Python 3.
Check fact: PIP packages is installed for Python 2 will not work for Python 3 and visa versa.
Details of PIP – pip show
Use pip show to check the details of installed package.
pip show
pip itself is one of the packages, so you can see the details as follows.
pip show pip
List of installed packages – pip list
List installed packages, including editables. Packages are listed in a case-insensitive sorted order.
List of installed packages –
pip list
List outdated packages
-o, --outdated
List uptodate package
u, --uptodate
A similar command, pip freeze, is also provided.
pip freeze
freeze does not output pip itself and packages for package management such as setuptools and wheel.
Install a package
pip install
Use pip install to install a package.
If a package is registered in the PyPI (the Python Package Index), you can specify its name and install the latest version.
pip install
Multiple packages can be installed at the same time.
pip install ...
You can also use == to specify a version, such as 1.0.0.
pip install ==
Update a package
pip install --upgrade
To update installed packages to the latest version, run pip install with the –upgrade or -U option.
pip install --upgrade
pip install -U
Update pip itself
The pip itself is also managed by pip.
You can update the pip itself with the following command.
pip install --upgrade pip
For the pip2 and pip3 commands, only the first pip should be replaced with pip2 or pip3.
pip3 install --upgrade pip
Uninstall a package
pip uninstall
Use pip uninstall to uninstall installed packages.
pip uninstall
Multiple packages can be uninstalled at the same time.
pip uninstall ...
Note: By default, you are asked before files are actually deleted.
Type y to uninstall.
If you add the –yes or -y option to the pip uninstall command, the confirmation is omitted.
pip uninstall --yes
pip uninstall -y
Check for dependencies: pip check
You can use pip check to verify that installed packages have compatible dependencies.
pip check
If a dependent package is not installed, or if it is installed but the version is not correct:
If you see such a message, you should install the corresponding package with pip install or update it with pip install -U.
If you find anything incorrect in the above-discussed topic and have further questions, please comment below.
Wrapping up!
Did you realize how easy it was to learn the details about PIP? It was as simple as confirming that you have the latest version of PIP and installing PIP or updating it and other things like that. PIP is a management system used to monitor and install software programs created using Python. It’s a shorter form of “preferred install software,” also known as “Pip installs packages.” PIP is a specific Python application that is a Python-specific program, and Python is a program to manage your PyPI installation of packages by using Command-Line.
Happy Coding 🙂