GAE项目

时间:2017-01-23 13:43:18

标签: python django google-app-engine jinja2

我正在使用python jinja2框架进行GAE,同时导入第三方库"烦恼"我收到导入错误。

我遵循GAE Installing a third-party library方法。

我的项目结构如

*projectfolder/
   *lib/
      *annoy/
   main.py
   app.yaml
   appengine_config.py

这是我的main.py代码

import os
import jinja2
from google.appengine.api import users
import webapp2
import csv
from jinja2 import Template
import ann_utils

JINJA_ENVIRONMENT = jinja2.Environment(
    # TODO: to add other directories here that contains the templates.
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
    extensions=['jinja2.ext.autoescape'],
    autoescape=True)

class Sent2Vec(webapp2.RequestHandler):
    """docstring for ."""
    def get(self):
        template = JINJA_ENVIRONMENT.get_template('sent2vec.html')
        self.response.headers['Content-Type'] = 'text/html'
        self.response.write(template.render()

ann_utils.py library

 from annoy import AnnoyIndex
import random

f = 40
t = AnnoyIndex(f)
for i in xrange(1000):
    v = [random.gauss(0, 1) for z in xrange(f)]
    t.add_item(i, v)

t.build(10)
t.save('test.ann')


u = AnnoyIndex(f)
u.load('test.ann')
print(u.get_nns_by_item(0, 1000))

的app.yaml

runtime: python27
threadsafe: ture

libraries:
- name: webapp2
  version: latest
- name: jinja2
  version: latest
- name: annoy
  version: latest

handlers:
- url: /.*
  script: main.app

appengine_config.py

from google.appengine.ext import vendor
vendor.add('lib')

以下是tracetrack:

INFO     2017-01-24 08:33:27,378 devappserver2.py:769] Skipping SDK update check.
INFO     2017-01-24 08:33:27,435 api_server.py:205] Starting API server at: http://localhost:60106
INFO     2017-01-24 08:33:27,451 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO     2017-01-24 08:33:27,451 admin_server.py:116] Starting admin server at: http://localhost:8000
ERROR    2017-01-24 08:34:53,286 wsgi.py:263] 
Traceback (most recent call last):
  File "/home/affine/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/affine/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/home/affine/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/home/affine/ML-Visualization/main.py", line 8, in <module>
    from ann_utils import create_tree
  File "/home/affine/ML-Visualization/ann_utils.py", line 1, in <module>
    from annoy import AnnoyIndex
  File "/home/affine/ML-Visualization/lib/annoy/__init__.py", line 15, in <module>
    from annoylib import *
  File "/home/affine/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 963, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named annoy.annoylib
INFO     2017-01-24 08:34:53,290 module.py:788] default: "GET / HTTP/1.1" 500 -

0 个答案:

没有答案