3

I am trying to use the python module flask, and I have successfully installed it with pip. I can run the following in the command prompt python terminal and in the python shell:

    from flask import Flask

It works just fine. However, when I try to run that exact same command in a saved python document, I get the following error:

    Traceback (most recent call last):
      File "C:\Users\Matthew\Desktop\flask.py", line 1, in <module>
        from flask import Flask
      File "C:\Users\Matthew\Desktop\flask.py", line 1, in <module>
        from flask import Flask
    ImportError: cannot import name 'Flask'

I have browsed the internet and stack exchange looking for a solution, but non have worked.

Matthew
  • 472
  • 2
  • 5
  • 12

1 Answers1

22

Rename the filename flask.py to other name; It prevents import of the third-party flask module because your file is searched first.

Also make sure there's no flask.pyc file remaining.

falsetru
  • 357,413
  • 63
  • 732
  • 636