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.
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 location | Virtual-environment location |
---|---|
~/Dev/project_a | ~/.virtualenvs/project_a |
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 for | Setting | Default location |
---|---|---|
Projects | PROJECT_HOME | ~/Dev or ~/Devel |
Virtual environments | WORKON_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.