Skip to content Skip to sidebar Skip to footer

Getting Error: 'No Module Named Flask' In VSCode Even When I Have Installed Flask

I want to debug an application using Python and Flask in VSCode. I have installed Flask and the app runs perfectly fine through cmd. But, when I try to debug it through VSCode, it

Solution 1:

This error message can occur if you installed the python3 version of flask but Visual Studio Code tries to run your project with python2.

Make sure to select the correct version of python in the editor. This can be done by running the command Python: Select Interpreter from the Command Palette (Ctrl+Shift+P).


Solution 2:

Sometimes you can get this error if you loaded Flask into a folder which has sub-files. For instance, if you loaded flask into the parent folder with the virtual shell instance but you're running your code in the child file (let's say parent is called crypto_files and inside that is a python source code file called blockchain.py ), then in order to get flask to run properly you'd have to run the file like this:

python crypto_files/blockchain.py

This allows your machine to see Flask running inside crypto_files but also run blockchain.py .

OR, it's possibly you could just reload Flask into the sub(child)file... blockchain.py and then you'd run it from within the subfile.

This complication is mainly due to modern "virtual instances" and shells which are basically like creating a virtual computer-machine inside your ACTUAL hard machine. Flask does this to avoid running everywhere, and since Flask is modular it allows each of your projects to run different modular configurations of Flask to suit each project precisely. The alternative would be awful: you'd have to load the fattest version of Flask with dozens of add-ons for each project, and so all your git and all your projects would have tons of extra code. Flask is built to be very small at the core to avoid this problem (too verbose!).


Solution 3:

Activate your virtualenv and run

pip3 install -r requirements.txt

to reinstall all packages inside the venv.

For some reason VS Code thought I was missing all my packages the first time I debugged even though the app was running fine locally.


Solution 4:

If you have installed flask in virtual environment, you should have activated it first.

source /path to env dir/bin/activate #in linux
workon 'name of env' #windows

Solution 5:

Another option is add sys.path.append('d:/programas/anaconda3/lib/site-packages') in c:\Users\Aditi.vscode\extensions\ms-python.python-2018.10.1\pythonFiles\experimental\ptvsd_launcher.py

Being that "d:/programas/anaconda3/lib/site-packages" should be modified by your local python packages.


Post a Comment for "Getting Error: 'No Module Named Flask' In VSCode Even When I Have Installed Flask"