When I run code importing a module, I get: ModuleNotFoundError: No module named '[module name]'
However, if I run the Python file in the terminal , in a virtual environment, it works.
I am working with:
- Python 3.10.6
- Vscode (version 1.75.1 - Universal)
- venv
- mac os Monterrey
My workflow for starting and working on a project (at the moment is learning exercises as I am a beginner) is the following:
- I create a folder for the project, using mac Finder
- In vscode I open the project folder
- In vscode terminal, inside the project folder, I create a virtual environment for the project, using: python3 -m venv env.[some name]
- I activate the virtual environment with: source ./env.[some name]/bin/activate
- Using the command palette, I select the interpreter of the virtual environment i just created
- In the vscode terminal screen, with the activated venv, I install modules using: python3 -m pip install [module name]
- Inside the project folder I create the .py files
I don't understand why running the code does not find the module, but running the Python file works.
I use this dropdown to either run code or run file in vscode