python
Pip

pip Commands Documentation

pip is the most widely used package manager for Python, enabling the installation, updating, and management of Python packages. Below are the key pip commands for managing packages in Python projects.


1. Install a Package

Installs a package from the Python Package Index (PyPI) or other sources.

pip install <pkg>
  • Related: Install a specific version of a package.

    pip install <pkg>==<version>

2. Uninstall a Package

Uninstalls a package and removes it from your environment.

pip uninstall <pkg>

3. Show Package Information

Displays detailed information about an installed package, such as version, location, and dependencies.

pip show <pkg>

4. Freeze Installed Packages

Outputs a list of all installed packages in the current environment along with their versions. This is often used to create a requirements.txt file for Python projects.

pip freeze > requirements.txt
  • Related: Install packages from a requirements.txt file.

    pip install -r requirements.txt

5. List Installed Packages

Lists all the installed Python packages and their versions.

pip list

6. Update a Package

Upgrades a package to the latest version available from PyPI.

pip install --upgrade <pkg>

7. Install a Package from a Local File

Installs a package from a local .tar, .zip, or .whl file.

pip install <path_to_file>

8. Install a Package from a Git Repository

Installs a package directly from a Git repository. This is useful when the package is hosted on GitHub or any other Git service.

pip install git+https://github.com/username/repository.git

9. Install a Package from a URL

Installs a package from a URL pointing to a .tar, .zip, or .whl file.

pip install <url>

10. Search for a Package

Searches for a package in the Python Package Index (PyPI).

pip search <pkg>

Note: This command is deprecated and may be removed in future versions of pip.


11. Check for Outdated Packages

Checks for outdated packages in the current environment and lists them with available versions.

pip list --outdated

12. Verify Installed Packages

Verifies the integrity of installed packages by checking for any inconsistencies or problems.

pip check

13. Install a Package from a Wheel File

Wheel files (.whl) are precompiled package files that allow faster installation. You can install a wheel file using pip:

pip install <pkg>.whl

14. Show the Installed Package Location

Displays the location of an installed package within your environment.

pip show --files <pkg>

15. Use a Proxy to Install Packages

If you're behind a proxy, you can configure pip to use a proxy server to install packages.

pip install <pkg> --proxy <proxy_url>

16. Disable Cache During Installation

If you want to avoid using the cache when installing packages, you can use the --no-cache-dir flag.

pip install <pkg> --no-cache-dir

17. Install Packages with Extra Index URL

If you want to install a package from a different index (other than PyPI), you can specify an extra index URL.

pip install <pkg> --extra-index-url <url>

18. Install a Package with Specific Python Version

If you have multiple Python versions installed, you can install a package for a specific Python version.

python3.8 -m pip install <pkg>