author Magesh

Projects in VirtualEnvWrapper

Magesh Ravi on March 25, 2023

VirtualEnvWrapper is commonly used by Python developers to manage their virtual environments. While many of them are familiar with the mkvirtualenv command and use it frequently, this article will focus on the less popular mkproject command and guide how to use it effectively.

How folders are organised

To start a new project, create a folder within the ~/Dev folder with the same name as the project. Then, create a virtual environment with the same name using the mkvirtualenv command.

For example,

cd ~/Dev
mkdir project_a
mkvirtualenv project_a
Project locationVirtual-environment location
~/Dev/project_a~/.virtualenvs/project_a


Benefits of using mkproject

Instead of performing the two steps above manually, use the mkproject command to create a project folder and virtual environment folder automatically.

Running the command mkproject project_b creates a folder in ~/Dev and a virtual environment folder in ~/.virtualenvs.

The PROJECT_HOME setting controls the project folder's location, and the WORKON_HOME setting controls the virtual environment folder's location.

Parent folder forSettingDefault location
ProjectsPROJECT_HOME~/Dev or ~/Devel
Virtual environmentsWORKON_HOME~/.virtualenvs


You can override the defaults as shown below.

export PROJECT_HOME=/path/to/your/projects-folder
export WORKON_HOME=/path/to/your/virtualenvs-folder

When starting a new Python or Django project, remember to use the mkproject command for a faster and more efficient setup.

This article summarises what we discussed in the Django Developers Guild monthly meeting on 26 Feb 2023. If you liked this post, share it with someone who might find it helpful.

Have a comment to share or a question to raise? Join our Discord server.