开发者

GAE 1.5.5 local SDK fails to run with python2.7 runtime

开发者 https://www.devze.com 2023-04-12 06:48 出处:网络
GAE 1.5.5 looks to have some excellent, long-waited for features. However, they\'re not working for me yet.

GAE 1.5.5 looks to have some excellent, long-waited for features. However, they're not working for me yet.

I've downloaded and installed GAE 1.5.5, and am using a degenerate "AAA" app to test.

Here's roughly my app.yaml (with various changes having been made for testing).

app.yaml

application: AAA # mystical creation.
version: alpha-1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /media
 static_dir: media/

- url: /favicon.ico
 static_files: media/images/favicon.ico
 upload: media/images/favicon.ico

- url: /admin
 script: AAA.app
 login: admin

- url: /.*
 script: AAA.app

skip_files:
- ^(.*/)?app\.yaml

libraries:
- name: django
 version: "1.2"
- name: jinja2
 version: latest
- name: yaml
 version: latest

I'm running this on Mac OS X Lion (10.7.1).

I hypothesize that I am not actually using the Python 2.7 runtime, in spite of the declaration in app.yaml to use it. I'm not quite sure how to validate this theory, but the errors I've encountered are consistent with it. These errors are reproduced below.

Python Path

When Google App Engine's Python Path is not set, the app engine runs using Python 2.6.6.

To fix this I set Python Path to /usr/bin/python2.7 in the Google App Engine preferences.

WSGI

I get the following error:

 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/
GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/
google/appengine/tools/dev_appserver.py in
GetParentPackage(self=<google.appengine.tools.dev_appserver.HardenedModulesHook
object>, fullname='AAA.app')
  2334
  2335       if self.find_module(fullname) is None:
=> 2336         raise ImportError('Could not find module %s' %
fullname)
  2337
  2338       return self._module_dict[parent_module_fullname]
builtin ImportError = <type 'exceptions.ImportError'>, fullname =
'AAA.app'
<type 'exceptions.ImportError'>: Could not find module AAA.app
     args = ('Could not find module AAA.app',)
     message = 'Could not find module AAA.app'

Where I've tried AAA.app as:

AAA.py:

 from google.appengine.dist import use_library
 use_library('django', '1.2') # otherwise we still get django 0.96

 from django.core.handlers import wsgi
 app = wsgi.WSGIHandler()

AAA/__init__.py

# same content as above

AAA/AAA.py

# same content as above

Note that I can continue to run CGI with app.yaml and AAA.py modified, mutatis mutandis. However doing so nevertheless results in those errors below:

Jinja2

When I run import jinja2 I get an ImportError.

Django2

Without:

from google.appengine.dist import use_library
use_library('django', '1.2')

I end up with Django 0.96.

Theory

Given the following:

  • http://code.google.com/appengine/docs/python/tools/libraries27.html states "The use_library() function provided by the google.appengine.dist package is unavailable in Python 2.7."
  • use_library works for me
  • use_library is required because the "libraries: {django: {..., version: "1.2"}} declaration does not set the django version to 1.2
  • Only Django 1.2 is included in the Python 2.7 runtime (per the libraries27.html link above)
  • I have to manually specify Python 2.7 in the Python Path in order for GAE to use Python 2.7
  • WSGI doesn't load the application 开发者_如何转开发properly
  • Jinja2 cannot be imported

I believe I am not really using the Python 2.7 GAE runtime (i.e. the app.yaml declaration is being ignored in the GAE 1.5.5 SDK).

I hope the above is a helpful description, and I'd be grateful for any thoughts as to what may be happening here – and potential solutions.


I'm have the same issue but on Windows, I posted on the Google App Engine forum and here is an official response I got:

The Dev server doesn't support 2.7 yet. Currently the only way to test 2.7 based code is on appengine


You can use the 2.7 runtime with the local SDK, but just not in threadsafe mode, or with your application defined like script: your.app. Instead use script: your_main_script.py.

For jinja2 and webapp2 which aren't available in the SDK, you can download them and place them in the SDK base directory, which is by default added to sys.path.

You won't be able to test the multithreading capabilities, but you can do everything else, and simply make the changes to app.yaml and your_main_script.py before you deploy.

EDIT: Also, I had to do os.environ[u'APPENGINE_RUNTIME'] = u'python27' in my your_main_script.py, to force the SDK to use webapp2.


Allbuttonspressed has recently posted this handy guide;
you can rundev_appserver on Python27 with threadsafe set to yes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号