Using pip to install Python packages
pipꜛ is another open source and command line based package installer and manager for Python like conda. We can use it to install Python packages from the Python Package Index (PyPI)ꜛ and other indexes. It works cross-platform, i.e., we can install it on any operating system (Linux, Mac, Windows). Learn in this post, how to use pip for installing and managing Python packages in your projects.
Before we begin, I recommend to create a virtual environment either with conda or with Python’s built-in
Does it matter for pip, how we have created a virtual environment?
No. For using pip it doesn’t matter, whether we have created the virtual environment with conda or with Python. With conda, just an extra step of installing pip into the virtual environment might be required:
conda install -y pip. Since pip usually comes along with the default Python installation, we do not need to extra install it, when we create the virtual environment with Python.
Installing and managing Python packages via pip
Installingꜛ Python packages via pip is quite easy:
pip install PACKAGENAME
pip install PACKAGENAME1 PACKAGENAME2 PACKAGENAME3
if you’d like to install several packages at once. For instance, a typical package installation for data scientists could again be
pip install numpy matplotlib scipy pandas seaborn pingouin notebook jupyter_contrib_nbextensions
We can searchꜛ for a specific package with pip,
pip search PACKAGENAME
or visit the PyPI websiteꜛ.
To listꜛ all installed packages, type:
We can remove installed packages via
pip uninstall PACKAGENAME
To list all outdated packages, type:
pip list --outdated
and to update a package:
pip install --upgrade PACKAGENAME
To update pip itself, just type:
pip install --upgrade pip
Install packages from a requirements.txt file
To install packages, that are specified in a “requirements.txt” file, simply type
pip install -r requirements.txt
where you can replace the argument “requirements.txt” by the path to the actual “requirements.txt” file.
Install code from GitHub: How to install Python code from GitHub, that is not available via conda or pip, is described in this post.