如何导入模块PyImgur Python

时间:2013-07-08 14:52:08

标签: python google-app-engine python-2.7

我是python的新手,我把它安装在C:\&我刚刚开始使用GAE的Hello World应用程序,我已经通过cmd python setup.py install下载了PyImgur,但我在gae日志中收到ImportError: No module named pyimgur错误。那么如何在main.py脚本中导入它呢?

的app.yaml

application: engineapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"

main.py

import webapp2
import pyimgur

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello world!')

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

这是GAE错误

INFO 2013-07-08 08:15:47,197 server.py:593]默认值:“GET / HTTP / 1.1”500 - INFO 2013-07-08 08:28:22,289 api_server.py:509]应用所有挂起的事务并保存数据存储 INFO 2013-07-08 08:28:22,289 api_server.py:512]保存搜索索引 2013-07-08 08:28:22(流程退出代码为0)

2013-07-08 08:28:23运行命令:“['C:\ Python27 \ pythonw.exe','C:\ Program Files(x86)\ Google \ google_appengine \ dev_appserver.py',' - -skip_sdk_update_check = yes',' - port = 8080',' - admin_port = 8000',u'C:\ fb-app \ engineapp']“ INFO 2013-07-08 08:28:29,868 devappserver2.py:528]跳过SDK更新检查。 INFO 2013-07-08 08:28:29,982 api_server.py:138]在http://localhost:59917启动API服务器 INFO 2013-07-08 08:28:29,989 dispatcher.py:164]启动服务器“默认”运行于:http://localhost:8080 INFO 2013-07-08 08:28:29,993 admin_server.py:117]启动管理服务器:http://localhost:8000

ERROR    2013-07-08 15:28:33,897 wsgi.py:219] 

Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 196, in Handle

    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 255, in _LoadHandler

    handler = __import__(path[0])

  File "C:\fb-app\engineapp\main.py", line 18, in <module>

    import pyimgur

ImportError: No module named pyimgur

INFO     2013-07-08 08:28:33,907 server.py:593] default: "GET / HTTP/1.1" 500 -

2 个答案:

答案 0 :(得分:1)

对于Google App Engine服务器上的模块,除official third party libraries中的模块外,您必须使用应用程序代码上传模块。

对于本地dev_appserver,他们必须驻留在您的PYTHONPATH

解决这两个问题的安全方法是将所需模块放在您的应用程序目录中,因为dev_appserver扩展了PYTHONPATH

答案 1 :(得分:0)

您需要在应用中包含pyImgur源代码。将模块包含在app目录(app.yaml所在的目录)或其子目录之一。