gpt4 book ai didi

python - 让 Flask 运行的问题

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:53 24 4
gpt4 key购买 nike

我开始学习 Flask。我想我已经正确安装了它,但它给我错误,我不知道为什么。

我得到了 Flask 网站的这个例子,我正在运行 Python 3.4

代码如下:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello World!"

if __name__ == "__main__":
app.run()

这是错误:

Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2195, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
during the handling of this error several other error occurred. Does this code not work on 3.4, or is something not installed right.

编辑:这是完整的错误

Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2195, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Python34\lib\site-packages\werkzeug\http.py", line 22, in <module>
from email.utils import parsedate_tz
File "D:\Documents\PythonScripts\More Advanced\email.py", line 1, in <module>
import smtplib
File "C:\Python34\lib\smtplib.py", line 47, in <module>
import email.utils
ImportError: No module named 'email.utils'; 'email' is not a package

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2195, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\Documents\PythonScripts\More Advanced\test.py", line 1, in <module>
from flask import Flask
File "C:\Python34\lib\site-packages\flask\__init__.py", line 17, in <module>
from werkzeug.exceptions import abort
File "C:\Python34\lib\site-packages\werkzeug\__init__.py", line 154, in <module>
__import__('werkzeug.exceptions')
File "C:\Python34\lib\site-packages\werkzeug\exceptions.py", line 71, in <module>
from werkzeug.wrappers import Response
File "C:\Python34\lib\site-packages\werkzeug\wrappers.py", line 26, in <module>
from werkzeug.http import HTTP_STATUS_CODES, \
File "C:\Python34\lib\site-packages\werkzeug\http.py", line 24, in <module>
from email.Utils import parsedate_tz
File "D:\Documents\PythonScripts\More Advanced\email.py", line 1, in <module>
import smtplib
File "C:\Python34\lib\smtplib.py", line 47, in <module>
import email.utils
ImportError: No module named 'email.utils'; 'email' is not a package

最佳答案

你有一个名为 email 的本地模块,它屏蔽了内置模块:

  File "C:\Python34\lib\site-packages\werkzeug\http.py", line 22, in <module>
from email.utils import parsedate_tz
File "D:\Documents\PythonScripts\More Advanced\email.py", line 1, in <module>

它由 werkzeug(Flask 使用的框架库)而不是 Python stdlib email 包导入。

重命名该文件;不要将屏蔽内置顶级模块的模块或包放在 Python 路径中。

关于python - 让 Flask 运行的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23937037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com