How To

How to Activate Venv

Pinterest LinkedIn Tumblr

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.

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.

open the command prompt box on Windows to activate Venv

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.

open the command prompt box on Mac to activate Venv

2. Type the below command.

$ source myenv/bin/activate

3. Now, the Venv will be activated on your Linux and macOS.

Frequently Asked Questions

1. How to deactivate Venv?

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.

2. Where is venv stored?

By default, it is stored inside the project directory under the folder name Venv. You can also choose a custom folder.

Write A Comment