簡體   English   中英

如何在appengine app中使用/usr/local/lib/python2.7/dist-packages中的模塊

[英]How to use module from /usr/local/lib/python2.7/dist-packages in appengine app

讓我首先說我不認為這實際上可行,但是,在我放棄努力吸引這個庫之前,我想確定一下。 所以我用easy_install添加了一個我在Github上找到的API庫。 我希望在我的appengine app中使用它。 我寫了一個簡單的測試處理程序,它將創建模塊主類的一個實例並打印一個請求。 我的dev_appserver將啟動但不會加載MainPage。 任何建議表示贊賞!

錯誤是:

ERROR    2013-06-21 04:24:00,450 wsgi.py:219] 
Traceback (most recent call last):
  File "/home/devin/google_appengine/google/appengine/runtime/wsgi.py", line 196, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/devin/google_appengine/google/appengine/runtime/wsgi.py", line 255, in     _LoadHandler
    handler = __import__(path[0])
  File "/home/devin/Projects/appengine/hackTheMidwest/perfectpet4me.py", line 4, in <module>
    import petfinder
ImportError: No module named petfinder
INFO     2013-06-21 04:24:00,455 server.py:593] default: "GET / HTTP/1.1" 500 -

這是我的主文件的代碼:

import os
import urllib

import petfinder # THE INSTALLED LIBRARY

from google.appengine.api import users

import jinja2
import webapp2


JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
    extensions=['jinja2.ext.autoescape'])

class MainPage(webapp2.RequestHandler):

    def get(self):
        template = JINJA_ENVIRONMENT.get_template('templates/index.html')
        self.response.write(template.render())

class TestPage(webapp2.RequestHandler):

    def get(self):
        # Instantiate the client with your credentials.
        api = petfinder.PetFinderClient(api_key='#####', api_secret='#####')
        pet = api.pet_getrandom()
        self.response.write(pet['name'])


application = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/test', TestPage),
], debug=True)

還有我的app.yaml:

application: ASDFASDFASDF
version: 1
runtime: python27
api_version: 1
threadsafe: true

- url: /.*
  script: perfectpet4me.application

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

你不能這樣做。 將您的第三方庫包含在應用程序的目錄中,並在應用程序中使用它。 在app引擎中部署時,它將與您的應用程序一起上傳。

這是我為谷歌應用引擎制作的gaenv工具的確切目的。 這是一篇博文,了解更多詳情: http//blog.altlimit.com/2013/06/google-app-engine-virtualenv-tool-that.html

但這里是摘要:你安裝它:

pip install gaenv
cd /to/your/project
gaenv

確保將您的第三方軟件包放入requirements.txt並安裝,它將創建一個符號鏈接,因此它將隨附上傳,因為appengine appcfg遵循符號鏈接。

您還可以在github上閱讀有關一切如何工作的代碼: https//github.com/faisalraja/gaenv

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM