Search code examples
pythondjangogoogle-app-enginevirtualenvdjango-nonrel

Django can't find can't find packages in virtualenv


I'm trying to set up a virtualenv for local development using Google App Engine and django-nonrel. I'm only trying to run the test app provided by django-nonrel for now.

The first time I tried, I got python manage.py runserver to work, but as soon as I tried to fetch a page from localhost:8080, it errored out on me, saying it couldn't find the pdb module:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2755, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2643, in _Dispatch
    base_env_dict=env_dict)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 682, in Dispatch
    base_env_dict=base_env_dict)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1717, in Dispatch
    self._module_dict)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1619, in ExecuteCGI
    reset_modules = exec_py27_handler(config, handler_path, cgi_path, hook)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1425, in ExecutePy27Handler
    import pdb
ImportError: No module named pdb

I tried copying modules from my main Python installation, and I also tried creating a new virtualenv which had access to site-packages. Both approaches worked up to a point - python manage.py runserver ended up not being able to find urllib.

On the other hand, python manage.py shell and then e.g. import pdb or import urrlib (or any other standard library, for that matter) work fine. What am I supposed to do?


Solution

  • The solution: don't use virtualenv at all, and put the libraries you're going to need (such as django) in your project directory. You're going to need that to deploy your app to GAE, anyway.