Python Virtualenv Setup on Windows

Recently, I switched from Mac to Windows laptop. I installed python 3.x and was thinking to build an application using Django. It’s always a good practice to use virtualenv when working on multiple projects. Installing various packages specific to each project clutters your machine and need clean up activity later on. With virtualenv you can use version specific packages and later on clean up would be very as you don’t want to keep unused packages on machine.

I was familiar about how to use virtualenv on Mac, I couldn’t find much information on how to setup virtualenv for windows, commands to activate and deactivate.

Assuming you have aleady installed python on windows, you might have already installed pip along with python. Check pip installation using cmd(command) window by typing:

pip --version

If pip is not installed go to Settings > Apps > Python, open to change the installation, include pip and save to install necessary pip files.

Steps to install virtualenv and activate:

  • Check/Install Python and pip
  • Install virtualenv
  • Install virtualenvwrapper-win
  • Create virtual env (mkvirtualenv project101)
  • Set project directory (setprojectdir)
  • Deactivate virtual env (deactivate)
  • Reactivating previous virtual env (workon project101)

Once you have confirmed that pip is installed on your machine. Install virtualenv using this command:

pip install virtualenv

If this was for Mac, you can use virtualenv directly. Since it’s windows, we have to install a wrapper on top of the virtualenv, this can be installed by

pip install virtualenvwrapper-win

Create virtualenv for the project with this command mkvirtualenv project101 in this project101 is your custom project name.

Create a project folder, navigate to the folder and set the current directory as project folder

setprojectdir

Install packages required for your project, these packages are specific to this virtualenv.

You can exit out of the virtualenv by deactivating

deactivate

To continue with existing virtualenv use workon as

workon project101

Hope this helps you to setup python virtualenv on windows and get started on your exciting py project.


Published 18 Jun 2019