How to create a virtual environment in Python?
- 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.
- How to send email as an alias in Gmail?
- How to stop Google from tracking your location?
- Command to check the Ubuntu version
- How to add a percentage in Excel?
- How to convert currencies in Google Sheets?
- How to voice type on Google Docs?
- What is Django framework?
- How to turn Google Assistant off?
- How to check the Python version?
- How to create a virtual environment in Python?
- How to change the directory in the Command Prompt?
- How to add a shortcode in WordPress PHP template file?
- Useful websites to research stocks
- How to check Linux uptime?
- How to check Linux last reboot time?