How To Use Python Pip

Before you read this tutorial, make sure you have latest Pip installed. To updgrade pip follow this tutorial https://www.nbshare.io/notebook/228803083/How-to-Upgrade-Python-PIP/

Pip Install Package

Let us say we want to install the package Scrapy

In [ ]:
pip install Scrapy

By default, pip will install the latest version of Package.

Pip check installed version of package.

In [2]:
pip show Scrapy
Name: Scrapy
Version: 2.5.0
Summary: A high-level Web Crawling and Web Scraping framework
Home-page: https://scrapy.org
Author: Scrapy developers
Author-email: None
License: BSD
Location: /home/abhiphull/anaconda3/envs/condapy36/lib/python3.6/site-packages
Requires: parsel, protego, itemloaders, service-identity, zope.interface, lxml, cryptography, pyOpenSSL, w3lib, itemadapter, h2, queuelib, PyDispatcher, Twisted, cssselect
Required-by: 

Pip find all available versions of package on PyPI

Let us say we want to find all the available packages of Scrapy on PyPi.

In [3]:
pip install Scrapy==
ERROR: Could not find a version that satisfies the requirement Scrapy== (from versions: 0.7, 0.8, 0.9, 0.10.4.2364, 0.12.0.2550, 0.14.1, 0.14.2, 0.14.3, 0.14.4, 0.16.0, 0.16.1, 0.16.2, 0.16.3, 0.16.4, 0.16.5, 0.18.0, 0.18.1, 0.18.2, 0.18.3, 0.18.4, 0.20.0, 0.20.1, 0.20.2, 0.22.0, 0.22.1, 0.22.2, 0.24.0, 0.24.1, 0.24.2, 0.24.3, 0.24.4, 0.24.5, 0.24.6, 1.0.0rc1, 1.0.0rc2, 1.0.0rc3, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7, 1.1.0rc1, 1.1.0rc2, 1.1.0rc3, 1.1.0rc4, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.4.0, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.7.0, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.8.0, 2.0.0, 2.0.1, 2.1.0, 2.2.0, 2.2.1, 2.3.0, 2.4.0, 2.4.1, 2.5.0)
ERROR: No matching distribution found for Scrapy==

As we see above, pip lists all the available packages, if we put '==' at the end of package name.

Pip install specific package

To Install a specfic package, just put the version name after the '==' sign as shown below.

To Install Scrapy version 2.4.1, execute following command.

In [ ]:
pip install Scrapy==2.4.1

Pip uninstall Package

To Uninstall package just type 'pip uninstall ' as shown below.

In [ ]:
pip uninstall Scrapy
Found existing installation: Scrapy 2.5.0
Uninstalling Scrapy-2.5.0:
  Would remove:
    /home/anaconda3/envs/py39/bin/scrapy
    /home/anaconda3/envs/py39/lib/python3.9/site-packages/Scrapy-2.5.0.dist-info/*
    /home/anaconda3/envs/py39/lib/python3.9/site-packages/scrapy/*
Proceed (y/n)?

As shown above, pip will prompt for (y/n). Press 'y' if you want to uninstall the Python package.