So I was trying to install the pytorch module and like any sane person I did the following:
python -m venv env
source env/bin/activate
Then I installed pytorch as given in the official documentation.
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Now If run python
in the terminal and ‘import torch’ it runs perfecty, also if I run any file importing pytorch with terminal, or inside vs code terminal(Run Python File) it works fine.
But when I run using code runner(Run Code) it throughs MooduleNotFoundError.
I have selected the correct Interpretor Path(/env/bin/python).
What is the problem here??
2
Answers
Try adding the following code to the setting.json
In fact, I think it’s better to use the
Run Python File
option provided by the Python extension.ModuleNotFoundError => When you try to import a module that is not installed or not found in the current Python path.
An incorrect Python environment or missing path configuration can cause this error in VS Code.