19👍
virtualenv really shines when you have a number of projects, and don’t want them to all share the same Python installation. For example, you could have two project with conflicting requirements.
9👍
“All non-python-only dependencies (PIL, psycopg2, …) are documented in a README and installed at the system level (apt-get install ….)”
Then you can’t have different dependencies for different projects, and not different versions of these dependencies for different projects.
One effect of that is that your local installs aren’t accurately reflecting the production machines, so you may have problems in reproducing production bugs, for example.
And if you install system tools that need one version, you are forced to use that same version everywhere, which may break your projects.
Also, undeleting modules needs to be done on the system python level. Virtualenv means you can set up a python install to test things without polluting the system install.
I’d definitely recommend having a separate python for your projects, and using something that isolates even that Python from the projects, like virtualenv or zc.buildout.
PIP is only an easier way to install modules, that also helps you uninstall them.
“there is no way I’m going to use the –no-site-packages option of virtualenv and install a compiler and all the build dependencies on my servers, I don’t think anyone is actually doing it anyway.”
No, I use zc.buildout, but it amounts to much the same thing, but less work. 😉
- [Django]-Invalid http_host header
- [Django]-How do I use an UpdateView to update a Django Model?
- [Django]-Django model CharField: max_length does not work?
3👍
I follow the method you have suggested without pip/virtualenv for my usual projects.
This allows me to put the packages in specific directory.
+ext
|
|------python packages
+source
|
|------ project code and packages
And usually in the startup script I update the PYTHONPATH
export PYTHONPATH="";
export PYTHONPATH="${PYTHONPATH}:${workingdir}/path/to/ext";
This has the advantage of keeping the project and dependencies self-contained. I echo, your thoughts here.
How ever, I find the use of virtualenv, when
- I have to experiment with
something new
. - Even better when I want to use
two different versions of package
and compare them. - Another use is where, I keep
different related packages that can be used across projects
.
Ex: Documentation: Some key packages, I have installed includes sphinx, pygraphwiz, nterworkX and some more visualization packages. I use it across projects and also keep it out of system level installation to keep it unpolluted.
I would also like you to checkout : Yolk. I find it nice in combination of pip/virtualenv.
You can list packages
yolk -l
Jinja2 - 2.5.5 - active
Markdown - 2.0.3 - active
Pycco - 0.1.2 - active
......
And check out pypi updates.
yolk --show-updates
Pycco 0.1.2 (0.2.0)
Sphinx 1.0.4 (1.0.5)
pip 0.8.1 (0.8.2)
- [Django]-Simple search in Django
- [Django]-Django py.test does not find settings module
- [Django]-Get request.session from a class-based generic view
2👍
Deploying with PIP/virtualenv:
According to you:
wget https://myserver.com/svn/projectfoo/tags/1.0.0STABLE/projectfoo-requirements.txt pip install -U -E projectfoo-venv -r projectfoo-requirements.txt
What I do: I also “freeze” packages but I do it with pip
and virtualenv
and check in the entire project; including the Python packages. So my deployment is exactly like yours:
svn checkout https://myserver.com/svn/projectfoo/tags/1.0.0STABLE/site
Working on a project with PIP/virtualenv:
According to you:
workon projectfoo cd path/to/project ./manage.py runserver 0:8000
What I do: Add a postactivate hook like this:
$ cat bin/postactivate
cd $VIRTUAL_ENV
./manage.py runserver 0:8000
$
And now, to change to the project:
workon projectfoo
- [Django]-Embed YouTube video – Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
- [Django]-Factory boy: define field that depends on other field
- [Django]-Django error message "Add a related_name argument to the definition"