- To create the new environment in the myenv directory, use the following command in Linux and macOS:
python3 -m venv myenv
- In Windows, the command to be used is as follows:
python -m venv myenv
This creates an environment in the myenv subdirectory of the current directory. The -m switch is used because venv is a Python module that is being executed.
- To switch to the new environment on Linux and macOS, run the following in the command line:
source myenv/bin/activate
- On Windows, we use the following command:
myenv\bin\activate
- If we need to install a package in the new environment, we use pip or pip3 as usual. For example, to install a molecule package using pip3, we execute the following command:
pip3 install molecule ...