chiggsy
chiggsy

Reputation: 8473

Installing certain packages using virtualenv

So, I want to start using virtualenv this year. I like the no-site-packages option, that is nice. However I was wondering how to install certain packages into each virtualenv. For example, lets say I want to install django into each virtualenv... is this possible, and if so, how? Does buildout address this?


Well it's not so much django, more like the django applications... I dont mind installing a version of django into each virtualenv... i was just wondering if there was some intermediate option to 'no-site-packages'

Upvotes: 2

Views: 3278

Answers (5)

simeon
simeon

Reputation:

I know where you're coming from with the no-sites-option. I want to use pip freeze to generate requirements lists and don't want a lot of extra cruft in site-packages. I also need to use multiple versions of django as I have legacy projects I haven't upgraded (some old svn checkouts (pre1.0), some 1.0, and some new svn checkouts). Installing Django in the global site-packages isn't really an option.

Instead I have a django folder with releases and a couple of different svn versions and just symlink to the appropriate version in the local site-packages. For ease of use I link to the local site-packages at the same level as the environment and then link in the appropriate django directory and any other "system" style packages I need (usually just PIL). So:

$ virtualenv pyenv
$ ln -s ./pyenv/lib/python2.5/site-packages ./installed
$ ln -s /usr/lib/python2.5/site-packages/PIL ./installed
$ ln -s /opt/django/django1.0svn/trunk/django ./installed

Now the following works:

$ source pyenv/bin/activate
$ python
> import django
> import PIL

Upvotes: 6

Alec Thomas
Alec Thomas

Reputation: 21113

I'd suggest using virtualenv's bootstrapping support. This allows you to execute arbitrary Python after the virtualenv is created, such as installing new packages.

Upvotes: 1

chiggsy
chiggsy

Reputation: 8473

I want to check out this project:

http://www.stereoplex.com/two-voices/fez-djangoskel-django-projects-and-apps-as-eggs

Might be my answer....

Upvotes: 0

Brian Clapper
Brian Clapper

Reputation: 26230

The other option (one I've used) is to easy_install Django after you've created the virtual environment. This is easily scripted. The penalty you pay is waiting for Django installation in each of your virtual environments.

I'm with Toby, though: Unless there's a compelling reason why you have to have a separate copy of Django in each virtual environment, you should just consider installing it in your main Python area, and allowing each virtual environment to use it from there.

Upvotes: 0

airportyh
airportyh

Reputation: 22688

If you want django to be installed on EACH virtualenv, you might as well install it in the site-packages directory? Just a thought.

Upvotes: 2

Related Questions