views:

26

answers:

2

I am using a Windows machine with python, django, and pinax installed.

I can import modules from any normal location (even if it's not in the actuall installed directory). However, I cannot import these same modules when I am in a virtual environment that I built for Pinax.

What are possible causes of this? What are possible solutions?

+1  A: 

To diagnose failure to import, try using the -v switch to python:

python -v my_program.py

It will show its attempts to import your modules.

Ned Batchelder
+1  A: 

As the summary says,

[[virtualenv]] creates an environment that has its own installation directories, that doesn't share libraries with other virtualenv environments (and optionally doesn't use the globally installed libraries either).

Yet you appear surprised that the virtualenv you've built "doesn't share libraries"... why are you surprised, when that not-sharing is the whole point of virtualenv?!-)

Once you've made a python virtualenv.py ENV, to keep quoting from the summary I've already pointed you to, "if you use ENV/bin/easy_install the packages will be installed into the environment".

So, do that to install all packages you need to be available for importing in the virtual environment.

(Assuming you've used the --no-site-packages option to make the virtual environment, you need to do that also for all packages you had installed "site-wide", since the purpose of that option is to exclude them for better control and isolation).

Alex Martelli
Thanks! I'd assumed that the virtualenv simply started by searching for modules in the virtualenv and if it didn't find it that it would go to the global site-packages location.I didn't use the no-site-packages so I'm not sure why it didn't look for my package in the global sitepackages folder. In any event i installed PIL as per your instructions in the virtual env and it works fine. Thanks again
DevX
@DevX, you're welcome. Not sure what made "no site packages" the default for you (it should be, but isn't;-), maybe you followed instructions or used a virtualenv-building script for Pinax and those instructions or that script included that flag. Anyway, glad I've been of help!
Alex Martelli
Just curious on best practices, do you usually install all your modules in a virtual environment for each project you work on?
DevX
@DevX, only for personal projects (at work we use a different system for defining projects, though it also demands explicit specification of each non-standard-library package being user in a project and won't actually let you build otherwise) -- it's a matter of proper "release engineering" discipline (not having a project succeed on a machine and crash on another because an extension was accidentally present globally on the first and missing on the second -- and that's just the start of it!-).
Alex Martelli