pip
is a tool to install Python packages and resolve dependencies automatically. This section lists a couple of things you can do with pip
:
To install a Python package, call pip
with the package name:
:::bash
pip install pandas
You can specify the exact version of a package:
:::bash
pip install pandas==0.25.0
First, create a file requirements.txt
in your project directory. The file should look similar to this:
:::text
pandas==0.25
numpy>=1.17
scikit-learn
requests
Second, ask pip
to install everything:
:::bash
pip -r requirements.txt
If a repository has a setup.py
file, you could install directly from git. This is useful to install branches, forks and other work in progress:
:::bash
pip install git+https://github.com/pandas-dev/pandas.git
When developing, you might want to pip-install a working copy. This allows you to import your package (e.g. for testing). Changes to the code directly take effect in the installation.
For the following to work, your project folder needs to have a setup.py
:
:::bash
pip install --editable .
This one prints all packages you have installed and their versions:
:::bash
pip freeze
To search for a pacakge, use grep
:
:::bash
pip freeze | grep pandas
pip
also removes packages:
:::bash
pip uninstall pandas
Usually, packages are stored in the site_packages/
folder. Where this one is depends on your distribution and your virtual environment.
You might want to check your PYTHONPATH
environment variable. To do so from Python, use:
:::python3
import sys
print(sys.path)
- The
conda
program (part of the Anaconda distribution) is often a viable alternative to pip - You find all installable packages on the Python Package Index pypi.org