[Fixed]-Why should i use vagrant if i use virtualenv?

26👍

The difference between virtualenv and Vagrant is that virtualenv is only about separate Python installations whereas Vagrant is about the whole machine.

  • virtualenv isolates the Python interpreter and the Python dependencies on one machine so you can install multiple Python projects alongside each other with their own dependencies. But for the rest of the machine the virtualenv doesn’t do anything: you still have global dependencies / packages that are installed using your Mac OS X / Linux package manager and these are shared between the virtualenvs.

  • Vagrant specifies the whole machine: it allows you to specify the Linux distribution, packages to be installed and actions to be taken to install the project. So if you want to launch a Vagrant box with multiple Python projects on that machine you’d still use virtualenv to keep the Python dependencies separate.

For example, a developer on Mac OS X and a developer on Ubuntu Linux can use virtualenv to keep their Python projects installed but they’d need to use Vagrant to locally launch the same machine (e.g., a Linux distribution which matches the deployed server) to run exactly the same Linux version with the same packages installed on it and with the same Python project installations.

So, to answer your question, the reason to use Vagrant is that it allows you to locally create a machine with the exact packages installed whereas virtualenv would only concern itself with the Python dependencies.

Leave a comment