Introduction to Python pip
In this article, we discuss the concept of pip in Python. In Python, pip is a standard package management system that is used to install and manage other software modules. In general, pip is a package manager for many Python packages or modules to install it to use in the code when required. In Python, pip is usually used to install and manage any additional packages or modules required which are not available in Python standard library or if the modules which we want to install are not in-built in Python. Pip usually comes pre-installed from Python versions 3.4 and above. This can be installed in the below versions by downloading the packages.
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 it is not present 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.
If pip is already present then the above command will return the respective Python pip version. Let us below 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 then 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 which are used for the development of frameworks, tools, and libraries. So by using pip which allows us to 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
In the above screenshot, we can see that the requests package is already installed and therefore it shows the path of that package.
The output can be seen in the console. In the above statement, we can see that pip was used with install command followed by the name of the package or module which we want 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. Install a particular version of the package or module version that is needed. That can be done as the below statement.
pip install requests = = version
In the above statement, we have to 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 versions 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.
In the above screenshot, we can see the list of packages and their version in the pip standard package. We can see the output in the above screenshot. The above statement will display the list of packages that are installed along with the versions of the installed package. We can see the output when the above statement is executed in the console. In the output, we can see that when the list command along with pip command then we can see the list of packages that are already installed in the current Python environment with their respective packages. Now let us see another command that can be used with pip such as the “show” command. This command can be used to display the information about any specified package or modules which are already installed packages in the Python environment. Let us demonstrate the use of 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. The output can be seen in the console when the above statement is executed. In the output, we can see the detailed information of 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. So we can see in the console in the output the last sentence displays that the library “requests” along with its version is uninstalled successfully.
In this article, we conclude that the pip in Python is used as a standard package for installing and managing the additional libraries of Python. In this article, we saw how to install pip, how to check if pip is already present in the python environment. In this article, we also saw how to use pip to install any Python library. We also saw how can we list the packages installed in the current python environment also we saw how we can display the information of the installed packages and also how to uninstall the Python libraries.
This is a guide to Python pip. Here we discuss the introduction, How to Use pip in Python, working of Python pip, with respective examples. You may also have a look at the following articles to learn more –