- Python pip
- Introduction to Python package index (PyPI)
- Package version
- What is pip
- Install a package
- List installed packages
- Uninstall a package
- List dependencies of a package
- Summary
- List all packages, modules installed in python – pip list
- 1. List all the packages, modules installed in python Using pip list:
- Syntax for pip list command :
- Some Examples of pip list command with options:
- 3. List all the packages, modules installed in python Using pip freeze:
- Author
- Related Posts:
- pip list#
- Options#
- Examples#
Python pip
Summary: in this tutorial, you’ll learn about Python pip and how to use it to manage third-party packages.
Introduction to Python package index (PyPI)
Python has a rich standard library that you can use immediately. In case you need a package that isn’t available in the standard library, you can find it on the Python Package Index.
The Python Package Index (PyPI) is the largest Python repository. It contains many Python packages developed and maintained by the Python community.
To find a package, you can use the search box. For example, to search packages that deal with HTTP requests, you can simply use the requests keyword.
The search result will show many relevant packages. To find detailed information about each package, you can click the corresponding link.
Package version
Python packages use semantic versioning which consists of three-part version numbers: major version, minor version, and patch:
major.minor.patch
Code language: CSS (css)
The patch number is incremented for minor changes and bug fixes that don’t change the way the package works.
The minor version is also incremented for releases that add new features that are backward-compatible.
The major version is incremented for the changes which are not backward compatible.
For example, the requests package has version 2.24.0 (at the time of this writing). It has the major version is 2, the minor version is 24, and the patch is zero.
If you use the version requests version 2.24.0 in your project, you can upgrade it to any version that has the major version 2, for example, 2.25.1.
If you install a package with a higher major version e.g., 3.0.0, your application may not work correctly.
What is pip
To download the package, you use the command described in the module:
pip is the package installer for python. Pip allows you to install packages from PyPI and other repositories.
Python comes with pip by default. To check if pip is available on your computer, you can open the command prompt (or Powershell) on Windows and type the following command:
It’ll show something like this:
pip 20.2.4 from C:\Users\username
>\AppData\Roaming\Python\Python38\site-packages\pip (python 3.8)Code language: CSS (css)
…where 20.2.4 is the version and C:\Users\AppData\Roaming\Python\Python38\site-packages\pip is the location of pip.
If you use macOS or Linux, you can launch the terminal and use the pip3 instead of pip :
Install a package
To install a package from PyPI, you use the following command on Windows:
pip install package_name>
Code language: HTML, XML (xml)
And change pip to pip3 on macOS and Linux:
pip3 install package_name>
Code language: HTML, XML (xml)
For example, the following command installs the requests package:
From now on, you can use the requests package in any project. For example, you can create a new project called pip-demo and use the requests package.
The following code uses the requests package to make an HTTP request to the https://pypi.org/ and displays the HTTP status code:
import requests response = requests.get('https://pypi.org/') print(response.status_code)
Code language: JavaScript (javascript)
To install a package with a specific version, you use the following command:
pip install package_name>
==version>Code language: HTML, XML (xml)
The following command installs the requests package version 2.20.1:
List installed packages
To list all installed packages, you use the following pip command:
pip list
Code language: PHP (php)
It’ll return a list of packages installed on your computer like this:
Package Version ---------------- --------- appdirs 1.4.4 autopep8 1.5.4 certifi 2020.6.20 chardet 3.0.4 colorama 0.4.4 distlib 0.3.1 filelock 3.0.12 idna 2.10 Pillow 8.0.0 pip 20.2.4 pycodestyle 2.6.0 requests 2.24.0
Code language: CSS (css)
To check what packages are outdated, you use the following command:
pip list --outdated
Code language: PHP (php)
Package Version Latest Type ---------- ------- ------ ----- setuptools 47.1.0 50.3.2 wheel
Code language: CSS (css)
It shows the package name, the installed version, and the latest version.
Uninstall a package
To uninstall a package, you use the pip uninstall command:
pip uninstall package_name>
Code language: HTML, XML (xml)
It’ll prompt you for a confirmation like this:
If you type y , pip is going to uninstall the package. Otherwise, it won’t do so.
List dependencies of a package
When you install a package and if that package uses other packages, pip will install the package and its dependency, and also a dependency of dependencies, and so on.
To show the dependencies of a package, you use the following command:
pip show package_name>
Code language: HTML, XML (xml)
The following command shows the dependencies of the requests package:
The Requires line lists out the packages used by the requests packages.
Requires: urllib3, chardet, idna, certifi
Code language: HTTP (http)
Summary
- Python package index provides third-party Python packages developed and maintained by the Python community.
- Use Python installer for Python (pip) to manage third-party Python packages.
List all packages, modules installed in python – pip list
There are three ways to get the list of all the libraries or packages or modules installed in python using pip list command, pip freeze command and help function .
All the three ways of listing all the packages installed in python are explained below along with we also explained.
- Pip list all the outdated package installed in python
- pip list all the up to date package installed in python
- pip list all installed packages in json format
- pip list installed packages along with package version
1. List all the packages, modules installed in python Using pip list:
open Anaconda prompt and type the following command.
This will get the list of installed packages along with their version in angular braces which is shown below
Syntax for pip list command :
Some Examples of pip list command with options:
c) List all outdated Packages that are not dependencies of other packages.
d) pip list – list all the packages installed using json formatting
f) pip list – python List packages that are not dependencies of installed packages.
g) pip list – python list all package that are upto date.
2. Get the list of all the packages in python Using Help function: To get the list of installed packages in python you can simply type the below command in python IDE
This will list all the modules installed in the system .
3. List all the packages, modules installed in python Using pip freeze:
This will get the list of installed packages along with their version as shown below These are the three different methods that lists the packages or libraries installed in python.
Author
With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark. View all posts
Related Posts:
pip list#
List installed packages, including editables. Packages are listed in a case-insensitive sorted order.
Options#
-o , —outdated # List outdated packages -u , —uptodate # List uptodate packages -e , —editable # List editable projects. -l , —local # If in a virtualenv that has global access, do not list globally-installed packages. —user # Only output packages installed in user-site. —path # Restrict to the specified installation path for listing packages (can be used multiple times). —pre # Include pre-release and development versions. By default, pip only finds stable versions. —format # Select the output format among: columns (default), freeze, or json. The ‘freeze’ format cannot be used with the —outdated option. —not-required # List packages that are not dependencies of installed packages. —exclude-editable # Exclude editable package from output. —include-editable # Include editable package from output. —exclude # Exclude specified package from the output -i , —index-url # Base URL of the Python Package Index (default https://pypi.org/simple). This should point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format. —extra-index-url # Extra URLs of package indexes to use in addition to —index-url. Should follow the same rules as —index-url. —no-index # Ignore package index (only looking at —find-links URLs instead). -f , —find-links # If a URL or path to an html file, then parse for links to archives such as sdist (.tar.gz) or wheel (.whl) files. If a local path or file:// URL that’s a directory, then look for archives in the directory listing. Links to VCS project URLs are not supported.
Examples#
$ python -m pip list Package Version ------- ------- docopt 0.6.2 idlex 1.13 jedi 0.9.0
C:\> py -m pip list Package Version ------- ------- docopt 0.6.2 idlex 1.13 jedi 0.9.0
$ python -m pip list --outdated --format columns Package Version Latest Type ---------- ------- ------ ----- retry 0.8.1 0.9.1 wheel setuptools 20.6.7 21.0.0 wheel
C:\> py -m pip list --outdated --format columns Package Version Latest Type ---------- ------- ------ ----- retry 0.8.1 0.9.1 wheel setuptools 20.6.7 21.0.0 wheel
$ python -m pip list --outdated --not-required Package Version Latest Type -------- ------- ------ ----- docutils 0.14 0.17.1 wheel
C:\> py -m pip list --outdated --not-required Package Version Latest Type -------- ------- ------ ----- docutils 0.14 0.17.1 wheel
$ python -m pip list --format=json [, , .
C:\> py -m pip list --format=json [, , .
$ python -m pip list --format=freeze colorama==0.3.7 docopt==0.6.2 idlex==1.13 jedi==0.9.0
C:\> py -m pip list --format=freeze colorama==0.3.7 docopt==0.6.2 idlex==1.13 jedi==0.9.0
When some packages are installed in editable mode, pip list outputs an additional column that shows the directory where the editable project is located (i.e. the directory that contains the pyproject.toml or setup.py file).
$ python -m pip list Package Version Editable project location ---------------- -------- ------------------------------------- pip 21.2.4 pip-test-package 0.1.1 /home/you/.venv/src/pip-test-package setuptools 57.4.0 wheel 0.36.2
C:\> py -m pip list Package Version Editable project location ---------------- -------- ---------------------------------------- pip 21.2.4 pip-test-package 0.1.1 C:\Users\You\.venv\src\pip-test-package setuptools 57.4.0 wheel 0.36.2
The json format outputs an additional editable_project_location field.
$ python -m pip list --format=json | python -m json.tool [ "name": "pip", "version": "21.2.4", >, "name": "pip-test-package", "version": "0.1.1", "editable_project_location": "/home/you/.venv/src/pip-test-package" >, "name": "setuptools", "version": "57.4.0" >, "name": "wheel", "version": "0.36.2" > ]
C:\> py -m pip list --format=json | py -m json.tool [ "name": "pip", "version": "21.2.4", >, "name": "pip-test-package", "version": "0.1.1", "editable_project_location": "C:\Users\You\.venv\src\pip-test-package" >, "name": "setuptools", "version": "57.4.0" >, "name": "wheel", "version": "0.36.2" > ]
Contrary to the freeze command, pip list —format=freeze will not report editable install information, but the version of the package at the time it was installed.