Menu
in ,

Python Virtualenv On Windows

python virtual environment

After installing Python on Windows as we talked about in our previous Python tutorial “A Simple Way To Installing And Run Python And PIP On Windows“.

We will install the Virtualenv tool to activate and deactivate Python Virtual Environment for our projects.

Install Virtualenv On Windows

After applying the Python installation guide on windows we can continue to install the Virtualenv tool using PIP, as the following

1- Run Windows PowerShell as an Administrator by:
Press Win Key + R. so a small window will pop up as shown in the screenshot below

Type in the popup window Powershell, then press Ctrl+Shift+Enter or press OK While holding Ctrl+Shift.

2- Run the command

PS C:\WINDOWS\system32> pip install virtualenv

The output will be similar to the following screenshot

Create Virtualenv On Windows

To create your project Virtualenv, go to the project folder, then run the Virtualenv command virtualenv env

PS C:\projects\crawler> virtualenv env
created virtual environment CPython2.7.18.final.0-64 in 4653ms
  creator CPython2Windows(dest=C:\projects\crawler\env, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, wheel=bundle, setuptools=bundle, via=copy, app_data_dir=C:\Users\WindowsUserName\AppData\Local\pypa\virtualenv)
    added seed packages: pip==20.3.4, setuptools==44.1.1, wheel==0.37.1
  activators NushellActivator,PythonActivator,FishActivator,BatchActivator,PowerShellActivator,BashActivator

Activate and Deactivate The Virtualenv

In the project directory and as described in the output message of the creating Virtualenv, the   Virtualenv command will create an env directory “dest=C:\projects\crawler\env” that contains activate.bat, and deactivate.bat scripts batch files used to activate and deactivate the Virtualenv for your project.

And so, to activate your Virtualenv go to the destination env\Scripts directory of your project As in our example  C:\projects\crawler\env\Scripts and run the activate.bat file.

And to deactivate run the deactivate.bat.

Installing Virtualenvwrapper Extensions On Windows

We will install Virtualenvwrapper-win for windows using PIP by running the following command

PS C:\projects\crawler> pip install virtualenvwrapper-win

Note that Virtualenvwrapper scripts only work probably in the regular Windows command prompt. and they may not work in the Powershell.

Leave a Reply

Exit mobile version