python path in webpage error message not virtual environment's

31 views
Skip to first unread message

knowledge_seeker

unread,
Feb 18, 2014, 5:11:02 AM2/18/14
to django...@googlegroups.com
I understand the importance of doing projects in virtual environments, but I am hitting one snag. 

When I have an error in django, and I get the generated webpage with an error message, it shows the 'normal' python path, site packages installed, etc. For example, I have jinja on my main installation, but not in the virtual environment. Yet, jinja shows up in this message as one of the site packages; similarly with the other python packages. Is there any way to show the python version (and location) and correct site-packages that are in the virtual environment in these error messages?

Russell Keith-Magee

unread,
Feb 18, 2014, 10:26:45 AM2/18/14
to Django Users
On Tue, Feb 18, 2014 at 1:11 PM, knowledge_seeker <sanjivch...@gmail.com> wrote:
I understand the importance of doing projects in virtual environments, but I am hitting one snag. 

When I have an error in django, and I get the generated webpage with an error message, it shows the 'normal' python path, site packages installed, etc. For example, I have jinja on my main installation, but not in the virtual environment. Yet, jinja shows up in this message as one of the site packages; similarly with the other python packages. Is there any way to show the python version (and location) and correct site-packages that are in the virtual environment in these error messages?

It sounds like you've built a virtualenv with --system-site-packages enabled. If you've got an earlier version of virtualenv (IIRC, version 1.4 or earlier), this was the default option when you created a virtualenv. When you construct a virtualenv in this way, it's an extension of your system - so anything in your system PYTHONPATH will also show up in your virtualenv.

If, on the other hand, you create your virtualenv with --no-site-packages (which is the default on more recent versions of virtualenv), the virtualenv is completely isolated. If you don't install a package in your virtualenv, it won't be available.

To check what version of virtualenv you have, the usual --version flag works; if you run --help, the description for --no-site-packages will tell you whether it's the default or not.

As for checking where a package has come from -- if you're in a Python shell, you can ask Python itself where it got a module. For example:

>>> import django
>>> django.__file__
'/Users/rkm/.virtualenvs/sample/lib/python2.7/site-packages/django/__init__.pyc'

tells you that I'm getting Django from the version installed in my "sample" virtualenv.

I hope that helps.

Yours,
Russ Magee %-)
 

Reply all
Reply to author
Forward
0 new messages