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 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?
- How to ZIP and UNZIP files in Linux?
- How to change the file owner and group in Linux?
- Protect your email address with Firefox Relay
- How to change the language in Microsoft Office?
- How to get Twitter dark mode on desktop and mobile?
- How to find a file in the Linux terminal?
- How to delete a directory in the Linux terminal?
- How to delete a file in the Linux terminal?
- Announcing Arclind Mindspace – Crash course platform for self-learners