Setting up venv for python apps on Windows

Very often, we would like to try python apps that we find on Github on our local machine. Installing the dependencies associated with the app might mess our system.

That’s where venv comes in. venv is a Python module that creates a unique environment for each task or project. It allows us to isolate the space for an app prevent the various dependencies we have to install for the app. This article is geared more towards python being installed on Windows OS.

which python

First, we check which version of python we have, to make sure that we have python installed. We use this as a form of verification.

which pip

We follow this with which version of pip is installed. We do this because though Python3 usually comes with pip preinstalled, sometimes the installation may be an older version of pip.

pip install virtualenv

If venv is not installed, start a command prompt and run the above command.

To start Virtualenv, head to your project location on your windows command prompt. We can create ta directory to hold the python app.

mkdir myapp

Create a directory for the python app

cd myapp

Navigate to the directory

virtualenv myapp

Choose the name of your virtual environment

C:\Users\'Username'\venv\Scripts\activate.bat

Activate the virtual environment using the “activate.bat” located in the \venv\Scripts\ directory:

(myenv) C:\path\to\current\directory

Once the virtual environment is activated, you’ll see the (myenv) at the beginning of the prompt.

deactivate.bat

To de-activate the virtual environment, do the following

«