Python Forum
VS Code debugger using wrong Python environment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VS Code debugger using wrong Python environment
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 471 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Installing python packages in a virtual environment Led_Zeppelin 1 753 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Something wrong with my code FabianPruitt 5 843 Jul-03-2023, 10:55 PM
Last Post: Pedroski55
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,242 May-10-2023, 02:13 PM
Last Post: Calab
  Python development environment standenman 3 1,598 May-04-2023, 07:24 PM
Last Post: snippsat
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,551 Mar-27-2023, 07:38 AM
Last Post: buran
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,243 Feb-24-2023, 06:14 PM
Last Post: deanhystad
Question Virtual Environment (using VS Code) Ashcora 4 13,466 Feb-15-2023, 07:17 PM
Last Post: snippsat
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,770 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Python Scripting Environment jpotter0 1 1,696 Nov-19-2022, 03:07 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020