Python - Using PIP
Using Python PIP package manager
Let us zoom through some of the commands and use cases for PIP the python package manager.
pip install "xyz"
Use the install command to install any of the modules that you need. Earlier you could search for the packages using the search command. It has now been discontinued. So you might get an error when you try to use their API for searching packages.
pip list
You can use the pip list command to list all the packages that you currently have installed.
pip uninstall "xyz"
You can use the uninstall command to uninstall any of the modules that you wish to remove.
pip list --outdated
You can use the list command with the outdated option to get a list of all outdated packages. You will get to know what version you have installed versus the latest one.
So how do you update the outdated packages?
pip install -U "xyz"
The install command with the -U option will let you upgrade the module to the latest version.
What's the use of the freeze command?
pip freeze
The freeze command will output all the modules installed in a format that is easier for the user to compile and make a requirements file. Suppose you need to ship the code to somebody. You need to tell them that these are the requirements that you need to have before you run my code. In that case, you will do a pip freeze; copy the contents and send him the requirements txt file.
pip freeze > requirements.txt
The above command will get the output from pip freeze and put the contents into the requirements text file.
Suppose you have sent Mr X this text file. How will he install all the requirements on his computer? Will he do it one by one?
pip install -r requirements.txt
The -r modifier will instruct the pip to install all the modules mentioned in the requirements text file.
How to download modules through pip?
There might be a use-case where you need to download the package from one computer and install it on another. We can use pip to download the files and save the files on a directory of choice using the following command.
pip download "xyz" --dest "C:/path.."
This will download all the necessary files in this folder. This folder can be zipped and shipped to the remote destination and there it can be installed using the requirements.txt file method that was discussed previously.
Hope you found this snippet useful for working with pip the python package manager.