Virtual Environments
Today we will learn about virtual environments. A virtual environment in python is a container in which all your code and other python packages reside. It allows you to keep your python configuration separate from other versions on your system. It is a good idea to always use a virtual environment when developing python code.
To create a virtual environment we will use the command:
python -m venv my_venv
Once the virtual environment has been created, you need to activate it. Once activated, your code runs inside the environment, including any packages you install. To activate the environment use one of the following commands:
Linus/mac OS:
source my_venv/bin/activate
Windows (Git-Bash):
source my_venv/Scripts/activate
To know you are inside the virtual environment your command prompt will have the prefix (my_venv). Now any packages you use will be stored in a folder structure inside your virtual environment.
To exit from the virtual environment, you type deactivate and the command prompt will no longer be prefixed by (my_venv).
Top comments (0)