当我尝试使用Python 3.3,Apache 2.2进行设置并在http://www.lfd.uci.edu/~gohlke/pythonlibs/使用mod_wsgi-3.4.ap22.win32-py3.3.zip时,这是错误日志
mod_wsgi (pid=4940): Target WSGI script 'C:/www/h.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=4940): Exception occurred processing WSGI script 'C:/www/h.wsgi'.
Traceback (most recent call last):\r
File "C:\\Python33\\Lib\\pkgutil.py", line 504, in find_loader\r
return importlib.find_loader(fullname, path)\r
File "C:\\Python33\\Lib\\importlib\\__init__.py", line 64, in find_loader\r
loader = sys.modules[name].__loader__\r
AttributeError: 'module' object has no attribute '__loader__'\r
\r
The above exception was the direct cause of the following exception:\r
\r
Traceback (most recent call last):\r
File "C:/www/h.wsgi", line 5, in <module>\r
application = Flask(__name__)\r
File "C:\\Python33\\lib\\site-packages\\flask\\app.py", line 331, in __init__\r
instance_path = self.auto_find_instance_path()\r
File "C:\\Python33\\lib\\site-packages\\flask\\app.py", line 622, in auto_find_instance_path\r
prefix, package_path = find_package(self.import_name)\r
File "C:\\Python33\\lib\\site-packages\\flask\\helpers.py", line 661, in find_package\r
loader = pkgutil.get_loader(root_mod_name)\r
File "C:\\Python33\\Lib\\pkgutil.py", line 482, in get_loader\r
return find_loader(fullname)\r
File "C:\\Python33\\Lib\\pkgutil.py", line 510, in find_loader\r
raise ImportError(msg.format(fullname, type(ex), ex)) from ex\r
ImportError: Error while finding loader for '_mod_wsgi_293471048e599ca28a13db229cd884c8' (<class 'AttributeError'>: 'module' object has no attribute '__loader__')\r
和浏览器显示“内部服务器错误”。
我不知道为什么,因为当我尝试使用Python 2.7,Apache 2.2和mod_wsgi-3.4.ap22.win32-py2.7.zip进行设置时,没关系
有人帮助我,非常感谢!
P.S:
httpd.conf设置
<VirtualHost *:80>
ServerName webmaster@localhost
WSGIScriptAlias / C:/www/h.wsgi
<Directory "C:/www">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
和我的应用
from flask import Flask
application = Flask(__name__)
@application.route('/')
def hello_world():
return "Hello"
if __name__ == '__main__':
application.run()
当我改为python 2.7时它可以正常工作
答案 0 :(得分:1)
我建议在#pocoo IRC频道上询问这个问题:
因为那是Flask的开发者所在。 Flask似乎依赖于Python 3.3下模块的__loader__属性,但mod_wsgi目前不添加一个。由于新模块导入程序的工作方式,Apache / mod_wsgi可能需要开始添加一个,但也不确定Flask是否应该容忍它不存在。
在此提供任何详细信息。
答案 1 :(得分:0)
我遇到了同样的问题,它似乎是与Python 3.3相关的问题,因为以下补丁指示: https://mail.python.org/pipermail/python-checkins/2014-March/128573.html
更新到Python 3.4似乎是一种选择。我也发现了这个解决方法,现在似乎有效: http://librelist.com/browser//flask/2013/9/18/problem-debugging-flask-under-python-3-3/