Quick Python 8: Virtual Environments
June 12, 2021
Project: quick-python
In this video, we learn how to create, manage, and remove Python Virtual Environments.
Here's a link to the source code.
Quick Tips
Commandspython3 -m venv <path>
Creates a virutal environment located at <path>
source <path>/bin/activate
Activates a virtual environment
deactivate
Deactivates a virutal environment
Bonus: Bash Alias for Quick SwitchingPaste this function into your
or ~/.bashrc
file and restart your shell. It assumes you keep your virtual environments in the ~/.bash_aliases
folder.~/venv
venv() { source ~/venv/$1/bin/activate}
Switch to the venv with
and get out of it by typing venv <NAME>
.deactivate
Example:
python3 -m venv ~/venv/my-envvenv my-env# do stuff in your environment. When done:deactivate
If you liked this video, check out the whole Quick Python series and be sure to sign up using the form below to get notified of new posts! Thanks for checking this one out.
Project: quick-python