Installing and upgrading Python packages

If you need Python packages that aren't installed systemwide then you can use pip to install those packages.

With a virtual environment

First create an environment if you don't have one already:

python3 -m venv ~/apps/appname/env

... then activate the environment and then run pip, eg:

source ~/apps/myapp/env/activate
pip install packagename

Without a virtual environment

Sometimes you might want to install a package globally in your home directory instead of in a particular environment. To do so, use the --user flag when running pip eg:

pip install --user packagename

To upgrade an installed package

If you've installed a package and need to upgrade it, include the -U option, eg:

pip install --user -U packagename

or activate your environment and run:

pip install -U packagename