Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should i use vagrant if i use virtualenv?

I read this question Do I need to use virtualenv with Vagrant? but i would like to know the opposite.

I program in and deploy to UNIX/Linux environments (respectively MAC OSX and Ubuntu) and I use virtualenv to keep environments isolated.

Actually I never encountered any problems but I saw some people and lots of tutorials that suggest to use them together, and I was wondering if and why should I use vagrant, can someone explain it to me?

like image 317
Jiloc Avatar asked Nov 21 '14 19:11

Jiloc


People also ask

Should I use Virtualenv or VENV?

These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.

Should I always use Virtualenv?

Always use a Virtual Environment Virtual environments let you have a stable, reproducible, and portable environment. You are in control of which packages versions are installed and when they are upgraded. You can have as many venvs as you want.

What is the point of Virtualenv?

virtualenv is a tool for creating isolated Python environments containing their own copy of python , pip , and their own place to keep libraries installed from PyPI. It's designed to allow you to work on multiple projects with different dependencies at the same time on the same machine.

When should I use Virtualenv?

virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.


1 Answers

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.

like image 182
Simeon Visser Avatar answered Oct 03 '22 07:10

Simeon Visser