BlendingJake
BlendingJake

Reputation: 155

Problems getting Flask to run

I have begun learning Flask. I think I got it properly installed, but it is giving me errors and I don't know why.

I got this example of of Flask's website and I am running Python 3.4

Here is the code:

from flask import Flask
app = Flask(__name__)

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

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

and this is the error:

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.

EDIT: here is the full error

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

Upvotes: 2

Views: 1896

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121854

You have a local module named email and it is masking the built-in module:

  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>

It is being imported by werkzeug (a framework library used by Flask), instead of the Python stdlib email package.

Rename that file; don't put modules or packages that mask built-in top-level modules on your Python path.

Upvotes: 4

Related Questions