Skip to main content
 首页 » 编程设计

python之如何导入模块 PyImgur Python

2025年05月04日10lvdongjie

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

应用.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" 

主.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] 在以下位置启动 API 服务器:http://localhost:59917 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 - 

请您参考如下方法:

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

对于本地 dev_appserver,它们必须驻留在您的 PYTHONPATH 中。

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