The Python virtual environment (Venv) helps the users to install Python packages in a particular location instead of using the whole system. It also prevents version conflict by isolating your project from other projects and system-wide projects. Venv makes it easy and installs the packages that are specific to your project. To isolate your projects, you need to create and activate Venv on your device first.
How to Create Venv
The steps to create Venv on your device depends on the Python version you currently run on your device.
Steps to Create Venv on Python 3.4+
1. Open the Command prompt on your device.
Information Use !!
Concerned about online trackers and introducers tracing your internet activity? Or do you face geo-restrictions while streaming? Get NordVPN - the ultra-fast VPN trusted by millions, which is available at 69% off + 3 Months Extra. With the Double VPN, Split tunneling, and Custom DNS, you can experience internet freedom anytime, anywhere.
2. Type the below command and click the Enter button.
$ python -m venv [directory name]
3. Now, Venv will be created for a particular directory.
Steps to Create Venv for other Python Versions
You can create Venv in all other versions using the virtualenv package. So first, you need to install the virtualenv with pip.
1. Open the Command prompt.
2. Type the command and click the Enter button. This will install the virtualenv package
$ pip install virtualenv
3. Then, type
$ virtualenv [directory name]
This will create Venv on the other Python versions.
How to Activate Venv Python
The method to activate Venv depends on the device you have. Do follow the below steps to activate Venv python on your device.
How to Activate Venv on Windows
1. Open the Command prompt box on Windows.
2. Use the directory name where you created Venv.
3. Execute the command
myenv\Scripts\activate.bat
4. Finally, Venv will be activated on your Windows
How to Activate Virtual Environment on Linux and macOS
You need to use a source command to activate Venv on macOS, Linux, and Linux variants (Ubuntu and Debian).
1. Open the Command box on your Linux or macOS.
2. Type the below command.
$ source myenv/bin/activate
3. Now, the Venv will be activated on your Linux and macOS.
Frequently Asked Questions
You can use deactivate command pipenv –rm to deactivate Venv in all the operating systems like Windows, Linux, and macOS. For Windows Powershell, use the $ deactivate or $ rm -r venv.
By default, it is stored inside the project directory under the folder name Venv. You can also choose a custom folder.
Disclosure: If we like a product or service, we might refer them to our readers via an affiliate link, which means we may receive a referral commission from the sale if you buy the product that we recommended, read more about that in our affiliate disclosure.