- October 24, 2020 at 1:02 PM #4141Santhosh Kumar DKeymaster@santhosh
venvmodule allows us to create a virtual environment within a site’s directory. Each virtual environment has its own Python library and can have its own independent set of installed Python packages. In this tutorial, I am going to use Python 3.8.2 and Command Prompt to create a virtual environment.
Create a virtual environment
First, we have to move to the directory within which we want to create a virtual environment. Use the command
venvto create a virtual environment. For instance, let’s create a directory called
environment, and create a virtual environment inside that directory as shown below.
python -m venv environment
Alternatively, we can directly mention the path of the directory within which we want to create a virtual environment there. For instance, the below command will create a directory called
environmentand creates a virtual environment inside the directory as per the mentioned path.
python -m venv /directory/site/environment
Activate a virtual environment
Once a virtual environment has been created, we need to activate it using a platform-specific script in the virtual environment’s directory. The following commands can be used to activate a virtual environment.
Platform Shell Command to activate virtual environment Windows Command Prompt
venvwith the path of the directory containing the virtual environment.
For instance, in this tutorial, we have created a virtual environment inside a directory called
environment. To activate it, we can use the Command Prompt specific activation script as follows.
Our virtual environment is now active as it shows the name
(environment)in the command line.
Learn more Python tips.
- You must be logged in to reply to this topic.