Issue importing Flask class

Hi. I have a rather specific issue when trying import flask into my project using the typical syntax:

from flask import Flask

PyCharm finds the module flask just fine, it even suggests it and displays the correct path of the file when I hover over it. But it seems it cannot find the Flask class.

The code runs fine, I can execute it using the the flask executable or the genererated run configuration. Visual Studio Code doesn't have any issues with the module, even when I use the same project and virtual environment. This issue only affects Flask, other modules and their classes can be imported.

I already tried the following steps:

  • Update PyCharm
  • Create a new project with pipenv and virtualenv
  • Create a project directory virtual environment using pipenv outside of PyCharm (it worked, but did not fix the import)
  • Invalidate PyCharm's caches
  • Check my project and Python file name (no collisions here)
  • Remove the system wide flask package
  • Install an older version of Flask
  • Check my file system permissions (my user can read and write everything)
  • Test the environment with vscode (everything works as expected)

I am starting to run out of ideas what else I could check and hope someone can give me a hint.

Comment actions Permalink

Hi, have you tried doing **File | Repair IDE...** ? It's a new option in 2021.3

The issue doesn't reproduce for me, by the way.

I wonder where are you navigated to if you ctrl+click on the `flask` module? Is it `site-packages/flask/`?

Comment actions Permalink

Thank you for your help. I just tried using the Repair IDE feature. It did not help unfortunately. Clicking on the flask module while holding shift lead me to "site-packages/flask/".

Since I had to do a bit of system maintenance on my PC anyway I took some more drastic measures. In the end, removing the pycharm folder under my users .config directory did the trick. Importing flask works fine now.


Please sign in to leave a comment.