Virtualenv + Django on OSX issue?

Hello everyone -

I've done a bit of googling, forums searching-etc to try and find a solution to this problem, but I can't seem to.  Hopefully I'm just doing something silly!

I have a pretty large and complex django project in a virtualenv that i've been working on for quite some time using a mix of different development environments.  I've started to play with pycharm and am very intrigued but have run into a strange issue.


If I use the virtualenv as my Project Interpretor, whenever I try to run this code from inside PyCharm I get the following error:

/Users/nick/envs/project/bin/python /Applications/PyCharm.app/helpers/pydev/pydevd.py --client 127.0.0.1 --port 52659 --file manage.py runserver --noreload 8000

PyDev console: using IPython 0.13.dev

pydev debugger: starting

Connected to pydev debugger (build 117.200)

/Users/nick/envs/project/lib/python2.7/site-packages/pytz/__init__.py:35: UserWarning: Module xmlrpclib was already imported from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.pyc, but /Users/nick/envs/project/lib/python2.7/site-packages is being added to sys.path

  from pkg_resources import resource_stream

/Users/nick/envs/projhect/lib/python2.7/site-packages/pytz/__init__.py:35: UserWarning: Module SimpleXMLRPCServer was already imported from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleXMLRPCServer.py, but /Users/nick/envs/project/lib/python2.7/site-packages is being added to sys.path

  from pkg_resources import resource_stream

Error: cannot import name utils

Process finished with exit code 1

The "utils" package missing is a reference to django.db.utils (which does exist.)
I've tried upgrading to newer dev branches of ipython and also tried to just remove ipython from the virtualenv -- both were no luck.  Also, the above seems to also be implying that /System/Library/Frameworks... is being added as well?
Strangely enough, if I don't use the VirtualEnv (and I make sure that all my packages are installed in the system-wide lib directory) it does work with no problems.
Anybody seen this issue before?
Thanks!
Nick
3 comments
Comment actions Permalink

Looks like a similar problem is tracked as http://youtrack.jetbrains.com/issue/PY-6333 in our issue tracker.

0
Comment actions Permalink

Hi Dmitry,

I saw that bug but I don't think its the same problem.  It looks like my site packages is in the virtualenv configuration.  I've attached a screenshot of all my paths.  The second to last path seems to be the site-packages of the virtualenv (called "trove").

Thanks again!
Nick



Attachment(s):
screen-capture-9.png
0
Comment actions Permalink

Interesting.  I got it to work.  This probably is because we have a very non-standard way of handling our settings.py file so we can deploy it across multiple environments.

For anybody else who runs into this issue:

We have a settings.py *and* a local_settings.py.  The local_settings.py contains various box specific settings that typically shouldn't be checked in or is box specific (passwords, etc.)

In our settings.py we have at the very bottom:

try:

    from local_settings import *

except ImportError:

    pass

Now inside local_settings.py, we had a few other imports that ultimately lead to a circular import.  Strangely though, this issue doesn't happen when I just run it from the CLI.  I wonder if the modules are loaded in a slightly different order in the CLI vs PyCharm....


Regardless, everything looks ok now.  Sorry for the noise!

-Nick

0

Please sign in to leave a comment.