Daniel Hills



Common venv commands in Python


Useful set of terminal commands for when using virtualenvs in Python. These cover about 99% of my use of venvs.

Create virtual env

python3 -m venv venv

(2nd argument specifies name of venv)

Note, you can specify python version like so:

virtualenv venv -p python3.6

Activate the env

source venv/bin/activate

Install packages on the venv from requirements.txt

pip install -r requirements.txt

Installing packages you need individually, e.g:

pip install pandas

Record packages installed on venv in requirements.txt using

pip freeze > requirements.txt

Make kernel available in Jupyter

python -m ipykernel install --user --name=<<env-name>>

Note the above makes the kernel available regardless of what environment you run jupyter notebook in.

deactivate env


List available (jupyter) kernels

jupyter kernelspec list

Remove kernel

jupyter kernelspec remove <<env-name>>