简体   繁体   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

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.

相关问题 如何从/usr/lib/python2.7/dist-packages/中的dir获取源软件包 - How to get source packages from dir in /usr/lib/python2.7/dist-packages/ OSError:[Errno 2]没有这样的文件或目录:&#39;/usr/local/lib/python2.7/dist-packages/pyduino-0.0.0-py2.7.egg&#39; - OSError: [Errno 2] No such file or directory: '/usr/local/lib/python2.7/dist-packages/pyduino-0.0.0-py2.7.egg' IOError:[Errno 13]权限被拒绝:&#39;/usr/local/lib/python2.7/dist-packages/finsymbols/SP500.html&#39; - IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/finsymbols/SP500.html' 错误:无法创建'/usr/local/lib/python2.7/dist-packages/virtualenv_support':权限被拒绝 - error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied virtualenv中的python3仍使用/usr/lib/python2.7/dist-packages中的库 - python3 in a virtualenv still uses library in /usr/lib/python2.7/dist-packages pip将2.7个软件包安装到/usr/local/lib/python3.2/dist-packages中 - pip installs 2.7 packages into /usr/local/lib/python3.2/dist-packages 为什么 pip install 模块在 /usr/local/lib/python3.4/dist-packages - why pip install module in /usr/local/lib/python3.4/dist-packages 它显示“[Errno 13]权限被拒绝:&#39;/ usr / lib / python2.7 / did-packages / Jinja2-2.8.egg-info / entry_points.txt&#39;”当试图安装烧瓶时? - It shows “ [Errno 13] Permission denied: '/usr/lib/python2.7/dist-packages/Jinja2-2.8.egg-info/entry_points.txt'” when trying to install flask? ImportError:无法从“变压器”(/usr/local/lib/python3.7/dist-packages/transformers/__init__.py)导入名称“BigBirdTokenizer” - ImportError: cannot import name 'BigBirdTokenizer' from 'transformers' (/usr/local/lib/python3.7/dist-packages/transformers/__init__.py) /usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43:未来警告: - /usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM