Flask, IIS, Python, wfastcgi Error occurred while reading WSGI handler: ImportError: cannot import name 'Flask'
Flask, IIS, Python, wfastcgi Error occurred while reading WSGI handler: ImportError: cannot import name 'Flask'
我的问题是我正在尝试部署一个简单的烧瓶 app.py :
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello from FastCGI via IIS!"
if __name__ == "__main__":
app.run()
那个web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="*" verb="*"
modules="FastCgiModule" scriptProcessor="C:\Python34\python.exe|C:\Python34\lib\site-packages\wfastcgi.py"
resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpErrors errorMode="Detailed" />
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="app.app" />
<add key="PYTHONPATH" value="D:\Web\flaskapp" />
</appSettings>
</configuration>
我收到错误错误:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "C:\Python34\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "C:\Python34\lib\site-packages\wfastcgi.py", line 616, in get_wsgi_handler
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "app.app" could not be imported: Traceback (most recent call last):
File "C:\Python34\lib\site-packages\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File ".\app.py", line 2, in <module>
from flask import Flask
ImportError: cannot import name 'Flask'
他不想导入我的库(不是全部!他可以像这样导入时间和其他)。
构建:
wfastcgi-3.0.0-py3.4.egg-info
Flask-1.0.2.dist-info
python 3.4
IIS 10.0.14393
非常感谢您的帮助。
仅需使用 python 3.4.2 x86。
我在尝试将 Flask 集成到 IIS 中时遇到了同样的问题。
python 安装路径在“C:\Program files”文件夹中,并且由于该路径有一个 space(在程序和文件之间)而发生错误。
我刚刚在没有 space 的目录(例如 C:\Python_39)上重新安装了 python,一切正常。
我的问题是我正在尝试部署一个简单的烧瓶 app.py :
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello from FastCGI via IIS!"
if __name__ == "__main__":
app.run()
那个web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="*" verb="*"
modules="FastCgiModule" scriptProcessor="C:\Python34\python.exe|C:\Python34\lib\site-packages\wfastcgi.py"
resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpErrors errorMode="Detailed" />
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="app.app" />
<add key="PYTHONPATH" value="D:\Web\flaskapp" />
</appSettings>
</configuration>
我收到错误错误:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "C:\Python34\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "C:\Python34\lib\site-packages\wfastcgi.py", line 616, in get_wsgi_handler
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "app.app" could not be imported: Traceback (most recent call last):
File "C:\Python34\lib\site-packages\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File ".\app.py", line 2, in <module>
from flask import Flask
ImportError: cannot import name 'Flask'
他不想导入我的库(不是全部!他可以像这样导入时间和其他)。
构建:
wfastcgi-3.0.0-py3.4.egg-info
Flask-1.0.2.dist-info
python 3.4
IIS 10.0.14393
非常感谢您的帮助。
仅需使用 python 3.4.2 x86。
我在尝试将 Flask 集成到 IIS 中时遇到了同样的问题。 python 安装路径在“C:\Program files”文件夹中,并且由于该路径有一个 space(在程序和文件之间)而发生错误。 我刚刚在没有 space 的目录(例如 C:\Python_39)上重新安装了 python,一切正常。