Relative Content

Tag Archive for pythonvisual-studio-codeflaskanacondamodulenotfounderror

ModuleNotFoundError in VSCode Conda Environment But Not When Opening VSCode Through Anaconda Prompt

I am relatively new to coding and more specifically Python. I was working on a course through Coursera and one of the projects that I decided to tackle on my local machine required me to install the Flask package. I created and activated a virtual environment using conda named “venv_Flask” and ran “pip install Flask” to install the package. The package installed and can be confirmed through “Flask –version” which outputs “Python 3.9.19 Flask 3.0.3 Werkzeug 3.0.3”. However, when I try to run the Python script in a .py file (the file has only one line “from flask import Flask”) in VSCode (where the selected interpreter is my conda environment “venv_Flask”), I get a “ModuleNotFoundError: No module named flask”. The interesting thing is however, that when I open Anaconda prompt, run “conda activate venv_Flask”, and then run “code” (which opens VSCode within venv_Flask), the same .py file runs without error. Any explanation/solution would be great. Thank you.