Updated June 14, 2023
Introduction to Python pip
In this article, we explore the concept of pip in Python. Pip serves as a standard package management system in Python, used to install and manage other software modules. It is a package manager for numerous Python packages or modules, allowing users to install and utilize them in their code as needed. In Python, it is common to use Pip to install and manage additional packages or modules that are not included in the Python standard library or are not built-in to Python. Pip usually comes pre-installed from Python versions 3.4 and above. You can install it by downloading the packages in the following versions.
Working of pip in Python with Examples
In this section, we will see in detail pip in Python. In Python, pip is a package used for installing and managing additional software modules or packages. Let us see in detail below with examples.
We can install pip if not in the installed Python IDE. We can check if pip is present by running the below statement or command in the console.
pip - -version
If pip is not present, then it will give the following error.
The above command will return the respective Python pip version if pip is present. Let us below the sample.
$pip - -version
pip 19.0.3 from C:\users\namitha\anaconda3\lib\site-packages\pip (python 3.6)
In the above screenshot, we can see the output of the pip version, which displays the version of Python pip.
If pip is not installed, we can download and install it through the link https://pypi.org/project/pip/. Through this link, we have to download pip.py.
To install, use the curl command and run the below statement:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then run the below statement
python get –pip.py
How to Use Pip in Python?
As we know, pip is a command-line program, and below is the basic syntax of pip is as follows:
pip <pip arguments>
Now we will see how pip can be used to install packages with pip. In Python, it contributes to an extensive number of packages or modules used to develop frameworks, tools, and libraries. So by using pip, we can download and install these packages or modules.
To install other Python libraries or modules, we need the “install” command and “pip” command to install the packages. Let us take the example below before installing the package “requests”.
pip install requests
The above screenshot shows that the requests package is already installed, showing the package’s path.
You can view the output in the console. The above statement demonstrates the usage of pip with the install command, followed by the name of the package or module you wish to install. By doing this, pip will try to download the latest version of the package or module specified in the pip statement. But for some programs, it will be necessary to customize the package with a particular version. You can install a specific version of a package or module by using the following statement.
pip install requests = = version
In the above statement, we must specify the version of the “requests” package or module by assigning the version number using the assignment operator (= =). So this way, we can install any version of the packages or modules using pip and install commands.
Now let us see another feature of pip. The pip can be used to list the installed packages or modules. To do this, we must use another command, “list” with pip. Let us see the below statement to list the packages in the current Python environment. Let us demonstrate this in the below statement.
pip list
The above screenshot shows the list of packages and their version in the standard pip package. We can see the output in the above screenshot. The above statement will display the list of installed packages along with the installed package’s versions. Executing the above statement in the console will display the output for you to observe. In the output, we can see that when the list command is along with the pip command, we can see the list of packages already installed in the current Python environment with their respective packages. Now, let’s explore another command that can be utilized with pip, which is the “show” command. The “show” command provides you with the ability to view information regarding a specific package or module that is already installed in the Python environment. Let us demonstrate the “show” command with pip in the below statement.
pip show requests
In the above screenshot, we can see the output of the above command, which displays the details of the requests package, such as name, version, summary, author, etc. When you execute the above statement, you will be able to view the output in the console. In the output, we can see detailed information on the requests package or module installed in the Python environment. Lastly, we will see if we no longer need any package or module then we can uninstall the packages or modules in Python by using the “uninstall” command. Let us demonstrate it in the below statement. Let us consider that we want to uninstall the “requests” library then we can do this as follows:
pip uninstall requests
The above screenshot shows how the uninstall command works with pip. The above statement when executed in the console. In the console output, the last sentence indicates a successful uninstallation of the “requests” library, including its version information.
Conclusion
This article concludes that pip is the standard Python package for installing and managing additional libraries. The article explains installing pip and checking its presence in the Python environment. Additionally, it demonstrates how to use pip to install Python libraries. We also saw how to list the packages installed in the current Python environment. We saw how we could display the information of the installed packages and how to uninstall the Python libraries.
Recommended Articles
We hope that this EDUCBA information on “Python pip” was beneficial to you. You can view EDUCBA’s recommended articles for more information.