![](/img/trans.png)
[英]How to get source packages from dir in /usr/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.