Managing Packages with pip


Basic example from Linux Installation

$ pip list

$ pip install <package_name>

$ pip uninstall <package_name>

$ pip install -U <package_name> # upgrades given package(s)

Where Are Packages Installed?

  • the sys.path variable
  • installing for other Python versions
$ python3
Python 3.9.12 (main, May  8 2022, 18:05:47)
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/site-packages']
>>>
  • directories that Python Interpreter searches to find module trying to be imported
$ pip3 show wheel
Name: wheel
Version: 0.37.1
Summary: A built-package format for Python
Home-page: https://github.com/pypa/wheel
Author: Daniel Holth
Author-email: dholth@fastmail.fm
License: MIT
Location: /usr/local/lib/python3.9/site-packages
Requires:
Required-by:

A Better Way to Call pip

$ python -m pip

User and system installs

pip tries to:

  • install package in system-wide location
  • only if that is not allowed, it will try to install for user specifically

To install package for user only:

python -m pip install --user babel

Getting Package Information with pip

python -m pip help <command>

Packages downloaded from PyPI (Python Package Index)

  • site also called the "Cheese Shop", after a famous sketch from Monty Python and because downloaded packages are in format called a "wheel" (like a wheel of cheese)
Made with Gatsby G Logo