让Flask运行的问题

时间:2014-05-29 15:31:38

标签: python python-3.x flask runtime-error

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

我得到了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

1 个答案:

答案 0 :(得分:4)

您有一个名为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路径上放置掩盖内置顶级模块的模块或包。

相关问题