Quick Python 8: Virtual Environments

June 11, 2021

In this video, we learn how to create, manage, and remove Python Virtual Environments.

Here’s a link to the source code.


Quick Tips

Commands

python3 -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 Switching

Paste this function into your ~/.bashrc or ~/.bash_aliases file and restart your shell. It assumes you keep your virtual environments in the ~/venv folder.

venv() {
    source ~/venv/$1/bin/activate
}

Switch to the venv with venv <NAME> and get out of it by typing deactivate.

Example:

python3 -m venv ~/venv/my-env
venv 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.


Your subscription could not be saved. Please try again.
Your subscription has been successful.

 Join our mailing list!

 Be the first to know about new articles and videos.