0

The problem is I have installed virtual environment and code runner. Installed all the packages required. When I run the file by code runner it does not detect package but run Python file detects package and does not give error!

halfer
  • 19,824
  • 17
  • 99
  • 186
Sahil Jain
  • 48
  • 7

1 Answers1

1

This is because the Code Runner takes the different python interpreter to execute the python script. You can check it through:

import sys
print(sys.executable)

Code Runner looking for the python interpreter from the system environment of PATH while your terminal in the VSCode has modified the value of the PATH. So it can choose the suitable python interpreter.

You can configure the code-runner in the settings.json to make it execute in the terminal to avoid this problem:

"code-runner.runInTerminal": true,
Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13
  • Understood this part, thanks. But what if I want the code runner to pick the same python as that of terminal in the output window. Do I need to declare in the environment variable settings? – Sahil Jain Jan 15 '22 at 11:29
  • @Sahil Jain Yes, it is. Code Runner has not provided the configuration to modify it. You can modify the system environment variable to achieve it. – Steven-MSFT Jan 17 '22 at 02:52
  • 1
    Hi Steven. Please encourage question authors to produce a self-contained example in their questions if you can. Stack Overflow is not designed to act as a forum, where a question author gets fleeting help - the point is to produce understandable questions (and helpful answers) that will be useful to readers in the future. In the above case, there is so little detail, it is impressive that you worked out what the author meant. I doubt any reader with the same problem would find it. – halfer Mar 12 '22 at 14:34