Skip to content
Advertisement

How do I fix this error in Spyder: No module named ‘flask’

Updated:

So after doing some digging I was able to find that if I add a ‘!’ before pip it allows me to run pip inside of Spyder. (I was unable to run pip inside the console originally. That is why below you will see I ran a version check on flask in a python cmd

Here I’m trying to install the latest version of flask just to make sure I have it installed.

If I run !pip install Flask I get the following:

Requirement already satisfied: Flask in {path}python37-32libsite-packages (2.0.1) Requirement already satisfied: Werkzeug>=2.0 in {path}python37-32libsite-packages (from Flask) (2.0.1) Requirement already satisfied: Jinja2>=3.0 in {path}spyderpkgs (from Flask) (3.0.0) Requirement already satisfied: itsdangerous>=2.0 in {path}python37-32libsite-packages (from Flask) (2.0.1) Requirement already satisfied: click>=7.1.2 in {path}spyderpkgs (from Flask) (8.0.0) Requirement already satisfied: colorama in {path}spyderpkgs (from click>=7.1.2->Flask) (0.4.4) Requirement already satisfied: MarkupSafe>=2.0.0rc2 in {path}spyderpkgs (from Jinja2>=3.0->Flask) (2.0.0)

That means that flask is definitely installed and can be reached by Spyder. When I run the file the following command is run:

runfile('{path_to_folder}/{file_name}.py', wdir='{path_to_folder}')

I still don’t know what is wrong with this, and I don’t use Spyder very often so I don’t believe it could be an environment variable that I messed with causing the issue.


Original Post:

So the issue is when I run my code in spyder I get the error below

ModuleNotFoundError: No module named ‘flask’

I’m importing flask at the top of my program. Below is what I get when I run my .py file in spyder.

from flask import Flask, jsonify

I checked to make sure I have flask installed and I do. I ran python in cmd to check which version of flask I was runnning.

>>> import flask
>>> flask.__version__
'2.0.1'

I’m not sure what else could be the issue. I’m not using a virtual environment so that isn’t causing an issue.

Advertisement

Answer

Problem


Here was the issue.

From what I can tell it’s related to a known issue in Spyder 5. When I started the project that I’m currently working on I updated to the latest version of Spyder. Apparently, there is an issue with some of the dependences in Spyder 5 and that was causing the issue.

You can read more about the exact issue here

Solution


I simply downgraded to Spyder 4 until the patch for this issue is released.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement