Problem
Flask cannot be used in PyCharm. There are two causes, and they produce similar symptoms.
- Flask cannot be selected as a project type in File | New Project, so a Flask project cannot be created.
- The
flaskpackage appears to be missing. An import offlaskfails withModuleNotFoundError: No module named 'flask', orwhere flaskon Windows returns nothing.
Cause
Flask project type is not available
Framework support for Flask is a PyCharm Pro feature. The PyCharm web frameworks documentation lists the dedicated project type, code completion, inspections, language templates and view-to-template navigation under Pro. The PyCharm editions page lists advanced support for Django, Flask and FastAPI as a Pro feature.
Every PyCharm installation starts with a 30-day Pro trial, as described in the installation guide. Flask support is present for the first 30 days. After that it is unavailable without a Pro subscription. Projects created during the trial keep their files, but the framework-specific assistance stops.
The flask package is not found
This cause is independent of the edition. The package is either not installed, or installed into a different interpreter than the one the project runs.
Resolution
Flask project type is not available
The free tier runs Flask code as ordinary Python. It does not provide the Flask project template, Jinja2 template navigation, Flask-specific inspections or the Flask run configuration type.
To develop a Flask application in the free tier:
- Create a plain Python project through File | New Project.
- Install the
flaskpackage into the project interpreter, as described below. - Create a regular Python run configuration that runs the application file.
To restore the framework support, activate a Pro subscription. Students and teachers are eligible for a free one through the Free JetBrains Student Pack. With Pro active, follow Creating a Flask project.
The flask package is not found
Install the package through the interpreter that the project uses:
python -m pip install Flask
A bare pip install Flask can install into a different Python installation when the machine has several. That is the most common reason the package looks installed but cannot be imported.
Verify the result by importing the library rather than by looking for the command:
python -c "import flask; print(flask.__version__)"
where flask on Windows, and which flask on macOS and Linux, locate the flask command-line executable rather than the library. That executable goes into the environment's scripts directory, which is often absent from PATH. An empty result therefore does not mean the package is missing.
If the import still fails, follow PyCharm can't install/import a package/library/module, which covers interpreter mismatch, permission and proxy cases.
Comments
0 comments
Please sign in to leave a comment.