How to use Python Virtualenv and Virtualenvwrapper on Windows? This guide will show you how to Install Python Virtualenv and Virtualenvwrapper. Virtualenv is a tool for creating isolated Python virtual environments, each with their own libraries and site-packages.
Virtualenvwrapper is a set of extensions to virtualenv for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies.
- Requirement Python3 Installed
First, open CMD and check Python version
If you can not find python version. Please install python3: https://www.python.org/downloads/
Install python virtualenv using pip
pip install virtualenv
After install virutalenv, if you create a virtual environment, it will be located inside your project. This is quite difficult to control your environment if you have many projects.
Virutalenvwrapper will help you to organize your environment in one place and control it easily.
pip install virtualenvwrapper-win
Create sample virtualenv
mkvirtualenv project01 mkvirtualenv project02
Now your virtual environments are located at C:\Users\yourusername\Envs
Press F1 –> Type Terminal: Select default profile –> Choose Command Prompt
If you use VSCode, open new terminal
Else you can use Windows cmd
Working with virtualenvwarpper
List environment that you can workon
Access to project01 virtual environment
After access project01 environment. Then, set project directory.
setprojectdir “Your Project Directory”
Repeat these steps for other projects
Access to project02 virtual environment
Set project02 directory
After setting project directory for project01 and project02. Now let quickly switch between them:
workon project01 –> The working directory will be change
workon project02 –> The working directory will be change
Let install some packages on project01
Switch to project01
workon project 01
python -m pip install Django
List installed packages
Switch to project02 to check installed packages
You can see that there is no package on project02
Some usefull Python Scripts for Operation: