This section covers the basics of installing Python packages.

Requirements for installing packages#

Before installing Python packages, a few prerequisites must be met.

  1. Make sure you are using the version of Python you want:

    $ python --version
    Python 3.10.6


    In iPython or a Jupyter Notebook you can find out the version with:

    In [1]: import sys
    sys.version_info(major=3, minor=10, micro=6, releaselevel='final', serial=0)


    If you use the system Python of your Linux distribution, you should first create a virtual environment with Python 3 and Pip.

  2. Make sure Pip is installed:

    $ pip --version
    pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
    1. If Pip is not yet installed, you can install it

      $ sudo apt install python3-venv python3-pip
      $ sudo apt install python-pip

Install Pipenv#

pipenv is a dependency manager for Python projects. It to install Python packages, but it simplifies dependency management. Pip can be used to install Pipenv, but the --user flag should be used so that it is only available to that user. This is to prevent system-wide packages from being accidentally overwritten:

$ python3 -m pip install --user pipenv

Successfully installed distlib-0.3.4 filelock-3.4.2 pipenv-2022.1.8 platformdirs-2.4.1 virtualenv-20.13.0 virtualenv-clone-0.5.7


If pipenv is not available in the shell after the installation, the USER_BASE/bin directory may have to be specified in PATH.

The USER_BASE can be determined with:

$ python3 -m site --user-base

Then the bin directory must be appended and added to PATH. Alternatively, PATH can be set permanently by changing ~/.profile or ~/.bash_profile, in my case:

export PATH=/srv/jupyter/.local/bin:$PATH

The directory can be determined with py -m site --user-site and then site-packages can be replaced by Scripts. this then gives, for example:


In order to be permanently available, this path can be entered in PATH in the control panel.

See also

Further information on user-specific installations can be found in User Installs.

Create virtual environments#

Python virtual environments allow Python packages to be installed in an isolated location for a specific application, rather than installing them globally. So you have your own installation directories and do not share libraries with other virtual environments:

$ mkdir myproject
$ cd !$
cd myproject
$ pipenv install requests
Creating a virtualenv for this project...

Virtualenv location: /srv/jupyter/.local/share/virtualenvs/myproject-CZKj6mqJ
Creating a Pipfile for this project...
Installing requests...
Adding requests to Pipfile's [packages]...