[英]How to use module from /usr/local/lib/python2.7/dist-packages in appengine app
Let me start by saying I don't think this actually can work, however, I want to be sure before I abandon my effort to pull in this library. 让我首先说我不认为这实际上可行,但是,在我放弃努力吸引这个库之前,我想确定一下。 So I used easy_install to add an API library I found on Github. 所以我用easy_install添加了一个我在Github上找到的API库。 I was hoping to use this in my appengine app. 我希望在我的appengine app中使用它。 I wrote a simple test handler that would make an instance of the module's main class and print a request. 我写了一个简单的测试处理程序,它将创建模块主类的一个实例并打印一个请求。 My dev_appserver will start but won't load the MainPage. 我的dev_appserver将启动但不会加载MainPage。 Any advice is appreciated! 任何建议表示赞赏!
The error is: 错误是:
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 -
And here's the code for my main file: 这是我的主文件的代码:
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)
And my app.yaml: 还有我的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
You cannot do that. 你不能这样做。 Include your third party library in the application's directory and use it in the application. 将您的第三方库包含在应用程序的目录中,并在应用程序中使用它。 It will be uploaded along with your application when deployed in app engine. 在app引擎中部署时,它将与您的应用程序一起上传。
This is the exact purpose of the gaenv tool I built for google app engine. 这是我为谷歌应用引擎制作的gaenv工具的确切目的。 Here is a blog post for more details: http://blog.altlimit.com/2013/06/google-app-engine-virtualenv-tool-that.html 这是一篇博文,了解更多详情: http : //blog.altlimit.com/2013/06/google-app-engine-virtualenv-tool-that.html
But here is the summary: you install it: 但这里是摘要:你安装它:
pip install gaenv
cd /to/your/project
gaenv
Make sure you have your thirdparty package into the requirements.txt and installed and it will create a symlink so it will be uploaded with it since appengine appcfg follows symlinks. 确保将您的第三方软件包放入requirements.txt并安装,它将创建一个符号链接,因此它将随附上传,因为appengine appcfg遵循符号链接。
You can also read the code on github on how everything works: https://github.com/faisalraja/gaenv 您还可以在github上阅读有关一切如何工作的代码: https : //github.com/faisalraja/gaenv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.