So here we will answer the most common question, what is PIP? So, basically, It is the standard package manager for python. It allows you to manage packages that do not come with a standard python library.
You may have encountered the situation where you are writing a code and notice that it’s already written by someone else. So here pip comes into play. For example, you are writing a complex code to count the number of characters in the file. But if you look at the python library this code is already written by someone else. You have to call that function to count the characters of the word.
Using pip, you can import/install all those functions which do not come with a standard python installation.
How to check the pip version
$ pip --version pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
If you see that pip is not installed on your system, you can easily install it using yum package manager.
For Python version 2.x
sudo yum upgrade python-setuptools sudo yum install python-pip python-wheel
For python version 3.x
sudo yum install python3 python3-wheel
Once you have pip installed and working, you can use all its functions from the command line. Let’s see some of the examples.
1. Installing packages with PIP
If you want to install any packages then you need to specify the package name, It’s just like installing packages using yum. See the example below to install packages.
pip install <pacakage-name>
let’s install the package boto3 which is used to create, configure, and manage AWS services. In my case, as you see below it’s already installed.
$ pip install boto3 Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: requests in /usr/local/lib/python3.6/site-packages (2.26.0) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.6/site-packages (from requests) (1.26.7) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/site-packages (from requests) (2021.10.8) Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.6/site-packages (from requests) (2.0.7) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.6/site-packages (from requests) (3.3)
2. Specifying package version while installation.
When you install the package using pip, it will mostly install the latest version however, if you want to install a specific version due to your code requirement then you can specify it too
$ pip3 install pyyaml==5.4.1
3. Display the version of currently installed packages.
$ pip show pyyaml Name: PyYAML Version: 5.4.1 Summary: YAML parser and emitter for Python Home-page: https://pyyaml.org/ Author: Kirill Simonov Author-email: [email protected] License: MIT Location: /usr/local/lib64/python3.6/site-packages Requires: Required-by: awscli
4. Display all the packages installed in the current environment.
$ pip list Package Version ------------------- --------- awscli 1.22.8 beautifulsoup4 4.10.0 boto3 1.20.8 botocore 1.23.8 certifi 2021.10.8 cffi 1.15.0 charset-normalizer 2.0.7 colorama 0.4.3 configparser 3.8.1 cryptography 35.0.0 ctap-keyring-device 1.0.6
5. Uninstalling a package.
Just like installation, it’s quite easy to uninstall as well.
pip uninstall <package-name>
6. Listing outdated package versions.
It’s quite easy to check if any of the packages installed are outdated. Just use the command below.
$ pip list --outdated Package Version Latest Type ------------------ --------- ----------- ----- awscli 1.22.8 1.24.10 wheel beautifulsoup4 4.10.0 4.11.1 wheel boto3 1.20.8 1.23.10 wheel botocore 1.23.8 1.26.10 wheel certifi 2021.10.8 2022.6.15 wheel cffi 1.15.0 1.15.1 wheel charset-normalizer 2.0.7 2.1.0 wheel colorama 0.4.3 0.4.5 wheel configparser 3.8.1 5.2.0 wheel cryptography 35.0.0 37.0.2 wheel
As I am learning python, I will be posting more about whatever I have learned. Just watch this space for updates 🙂