Create Python environment with Venv
Python environments (venv
):
For this type of environment, the only requirement for your computer is to have a version of Python installed on it. venv
is a Python module that supports lightweight virtual environments.
If you have not yet installed Python on your computer, we strongly recommend you install it via distribution software manager. This way of installing python is outdated.
For this type of environment, you need to be familiar with how the terminal works, how you can move from one folder to another, and the Python versions you have installed. If you are unfamiliar with these requirements, please refer to the How to use Anaconda section.
From Python 3.3 onwards, venv
should be included in the commands available. To create a virtual environment with this, please open your terminal:
macOS
To enter the terminal, you can search it directly from the Launchpad or application folder. Type Command
+ Space bar
and type terminal for a shortcut. First, we must ensure you are in the folder where you want to save the environment. When you open the terminal, you should see only your user name:
For this example, I am going to access my Documents folder. You can access whatever folder you wish to save your environment on.
If you save a virtual environment with the same name in the same folder, the terminal will interpret it as you want to rewrite it, and you will lose the information from the previous one. Before creating new environments, make sure that the name and folder you choose differ from previous ones.
python -m venv [name of the environment]
Inside of the brackets, you can change it to whatever name you want. Just make sure that the name of the environment is something easy to remember, or write it down somewhere. The name should also follow the terminal rules: if you are going to name something with more than one word, you need to hyphenate the words with an underscore (_).
- Example:
python -m venv example_environment
.
The way you activate it is while inside the folder where you created the environment, call source [name of the environment]/bin/activate
. The name in front of the dollar sign should change to the name of the environment you are currently in.
- Example:
WINDOWS OS
For the Windows OS you also need to have previously installed Python.
If you installed Python by downloading the installer directly from the Python page, you might need to add the path to the environment variables of your computer. Please see the section on how to do that in the "Add path to environment" section. If you are not familiar with the path and what it means to add it to the environment variables, please continue with the next steps.
If you have Python already in your Path variables, you can just use the same arguments as the macOS instructions.
- Example:
python -m venv example_environment
Please note that the same rules apply to Windows, so make sure to name the environment something unique and easy to remember, and also select the correct folder for your environment.