简体   繁体   中英

Why is the GAE python SDK using the system's python while in a virtualenv?

I am inside a virtualenv. I have installed the GAE python SDK following the documentation . As per the instructions, the SDK is not directly on the virtualenv, but is in the path.

I have installed some (non-vendored, that is, in the virtualenv) packages and I am starting the GAE development server:

» dev_appserver.py app.yaml

But this crashes when processing a request with:

  ...
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/foo/bar/appengine-django-skeleton/mysite/settings.py", line 105, in <module>
    import dj_database_url
ImportError: No module named dj_database_url

What I have already verified:

  • the virtualenv is active
  • the package is installed in the virtualenv
  • the active python is the one in the virtualenv
  • the package can be imported when on the python shell
  • dev_appserver.py has on the first line #!/usr/bin/env python , which should be telling the system to use the active python (the one from the virtualenv!)

Why is /usr/lib/python2.7/importlib/__init__.py being used at all? This does not belong to the active python (the one on the virtualenv)!

EDIT

There is a project to install the sdk on a virtualenv, but it's outdated. Is there a more recent method to accomplish this?

In addition to dizballanze's answer , I instead prefer to keep everything installed in my virtualenv and then symlink my virtualenv's site packages to the lib folder with something similar to:

ln -s env/lib/python2.7/site-packages lib

which results in a folder whereby my devappserver uses the virtualenv 's packages

├── env
├── lib -> env/lib/python2.7/site-packages

You can read more of my approach at https://www.jeffgodwyll.com/posts/2015/google-appegine-vendoring-done-right/

EDIT

App engine uploads all files in the project directory. To prevent app engine from uploading the entire virtualenv let it through the skip files section of your app.yaml :

skip_files:
- ^env$  # virtual environment's folder

GAE does not currently support virtualenv . To use packages you could:

  • write a list of needed packages supported by GAE runtime in app.yaml
  • install third-party packages to lib/ directory (pure python packages only) and add these code to appengine_config.py :

     from google.appengine.ext import vendor # Add any libraries installed in the "lib" folder. vendor.add('lib') 

Read more in GAE documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM