For every project and every stage (dev, prod, ...) I use a different linux user. I can use pip and the --user
option, to install packages in $HOME.
My isolated environment comes form different linux users.
Which benefits could I get from virtualenv? Up to now, I see no reason to use virtualenv. But maybe I am missing something.
Linux user names are build like this: project_name_S and S is the stage (dev, qual, prod, testing). Each stage can be on a different host.
Update:
More than three years after asking this question: I use virtualenv now. The user-environment was buggy. Maybe it has better support now. But nothing stops you from creating a virtualenv in $HOME :-)
Virtualenv's are great for managing dependencies. Config files (or settings files) are very good for managing variable differences between environments. (e.g db location e.tc)
The python hitchhikers guide is very good and worth a 20 min read. http://docs.python-guide.org/en/latest/index.html
See this section on virtual envs.
http://docs.python-guide.org/en/latest/dev/virtualenvs/
If you just want to use different home or env mode variables you could just set it before you run the python code.
PROD_MODE=PROD python example.py
example.py would then look for the PROD_MODE variable like so.
import os
print os.environ['PROD_MODE']
So do you need a virtualenv?
I would strongly recommend it. So you have Django working and you've imported some other libraries (i also strongly recommend pip) and everything is working on your machine. Your path is setup and your code can resolve to the code using PATH and PYTHON_PATH. Brilliant!
Now you come to deploy on another machine (maybe aws, an linux server or similar) or a fellow developer wants to help code on your project. How do they make sure the env on there machine is setup just the same as yours and how do you ensure you deploy with the same env you tested all your shinny new code with? A virtualenv does this for you! You just port or recreate the virtual env on the new machine any everything works just as tested/built.
In short a virtual env helps you ensure you don't have a headache in remembering all your imports, installs and path settings when you release/deploy code.
Creating a virtualenv sould be quicker and easier than creating a new user. I would not recomend switching for existing projects, but consider it for new projects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With