This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 2: Virtual Environments

Managing multiple environments

face Josiah Wang

The main recommendation is to create a virtual environment for each project that you work on, in the project folder itself. This assumes that you are a software developer working on lots of projects! So your aim is to have a virtual environment for each project.

Technically, you can create a virtual environment anywhere on your hard drive. You just need to be able to find it easily to activate it when needed!

For example, you could dump all your virtual environments in a single folder, say ~/.venv/. This will allow you to have environments not specific to a project. Perhaps you might want a virtual environment limited to all your scientific experiments, another with just PyTorch, another with Tensorflow, another for your computer vision experiments, etc.

Instead of the built-in venv that comes with Python, you can also create and manage your environments using the virtualenvwrapper tool. This makes it easier to manage your environments, especially if you prefer to put all virtual environments in a single folder as mentioned. For example, you will be able activate a virtual environment simply with a workon my_env command. This tool does not come with Python though, so you will have to install it separately (discussed in the next chapter!)

You can also use a distribution like Anaconda, which has virtual environment management capabilities via its conda tool. Note that you might not always be able to get the latest version of a package as conda uses its own distribution system!