Daniel Hills

Logo

๐Ÿšดยท๐Ÿ’ปยท๐Ÿ““ยท๐Ÿ“ˆ

View My GitHub Profile

Common venv commands in Python

2021-06-20

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

deactivate

List available (jupyter) kernels

jupyter kernelspec list

Remove kernel

jupyter kernelspec remove <<env-name>>