Python Forum

Full Version: VS Code debugger using wrong Python environment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I hope you can help me persuade the VS Code debugger to use the right environment.
Trying to run this sample file, mintest.py:

import numpy
import vg
I have a settings.json file in the same folder as mintest.py:

{
    "python.pythonPath": "C:\\Users\\xxxx\\Code\\hearo\\.env\\Scripts\\python"
}
When the virtual environment is activated from the terminal mintest.py runs fine from the terminal.

When mintest.py is run from the debugger (F5) I get this error:

Error:
Exception has occurred: ModuleNotFoundError No module named 'numpy' File "C:\Users\xxxx\Code\hearo\mintest.py", line 1, in <module> import numpy
I can see from the text added to the terminal by the debugger that it is not using the pythonPath I specified, but using the global python installation (hence the import error).

Output:
PS C:\Users\xxxx\Code\hearo> C:; cd 'C:\Users\xxxx\Code\hearo\\'; & 'C:\Users\xxxx\AppData\Local\Programs\Python\Python39\python.exe' 'c:\Users\xxxx\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\lib\python\debugpy\launcher' '50817' '--' 'c:\Users\xxxx\Code\hearo\mintest.py'
I have tried:
  • Putting the python.pythonPath setting in the launch.json file instead. I get the error:
    Error:
    Property python.pythonPath is not allowed.
  • Selecting the interpreter using Command Palette before running the debugger I get this error:
    Error:
    The Python path in your debug configuration is invalid.

Any tips on what I'm doing wrong much appreciated.