Python “GAE”;没有名为urllib的模块;
每当我试图通过python在GAE上运行示例代码时,我都会遇到这个错误Python “GAE”;没有名为urllib的模块;,python,macos,google-app-engine,Python,Macos,Google App Engine,每当我试图通过python在GAE上运行示例代码时,我都会遇到这个错误 File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRe
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
description)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cgi.py", line 31, in <module>
import urllib
ImportError: No module named urllib
INFO 2012-04-15 04:44:54,345 dev_appserver.py:2884] "GET / HTTP/1.1" 500 -
我在Mac OSX 10.6.8(Snow Leopard)上运行,使用的是Python 2.7.3,我不知道为什么导入的
urllib
不起作用,但是在您的示例代码中,您没有使用该模块,所以您真的不需要导入它。不确定这有多重要,但是堆栈跟踪中的文件夹结构似乎暗示您使用的是Python2.6,而您说的是2.7.3。也许您需要使用最新版本的Python显式运行脚本。有趣的是,它是一个内置模块(cgi.py),抛出了错误。urllib就在那里!我不明白为什么会这样
此外,雪豹还将python 2.6安装到/system/Library/Frameworks/python.framework/Versions/2.6,但我安装到的是/Library/Frameworks/python.framework/Versions/2.7
据我所知,我需要更改的只是GAE首选项中的Python引用。这很有效。有趣的是,它是一个内置模块(cgi.py),抛出了错误。urllib就在那里!我不明白为什么会这样!
import webapp2
import urllib
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)