Search code examples
pythonimporterror

how can i fix errors about import in my code


from app import app

When i do this, the error occurs.

E:\python\python.exe "C:/Users/user/PycharmProjects/dash exercise/dash-test/apps/Spreads.py"
Traceback (most recent call last):



 File "C:/Users/user/PycharmProjects/dash exercise/dash-test/apps/Spreads.py", line 19, in <module>
    from app import app
ImportError: cannot import name 'app' from 'app' (E:\python\lib\site-packages\app\__init__.py)

Process finished with exit code 1

Solution

  • You probably just need import app.

    It appears you're using PyCharm, so here's another tip. In the code itself, you can try to remove the import statement from the top of the file, and then, wherever the reference is in your code, it should have a red underline to indicate an error --In this case, a missing import. You can put your cursor on the red-underlined word, and press ⌥ ↩ on MacOS or Alt+Enter on Windows, and PyCharm will import the reference correctly for you. This is expecially useful when you have a complicated module structure.