Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask import error "cannot import name 'Flask'" [duplicate]

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.

like image 358
Matthew Avatar asked Jan 25 '26 11:01

Matthew


1 Answers

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.

like image 92
falsetru Avatar answered Jan 27 '26 01:01

falsetru