Skip to content

No-config debug uses default system Python on MacOS, not the active Python in terminal #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
taldcroft opened this issue Feb 11, 2025 · 17 comments
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@taldcroft
Copy link

taldcroft commented Feb 11, 2025

Running VS code on MacOS, for a script go.py:

import sys
print(sys.prefix)

I get the following in a VS code integrated terminal where I have activated a Python 3.12 conda environment:

$ python -V
Python 3.12.8
$ python go.py
/Users/aldcroft/miniconda3-arm/envs/ska3-flight-2025.0rc2
$ debugpy go.py
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9

If I use the traditional configured debug in VS code, then I get the expected results (Python 3.12.8 from my conda env). I had thought that no-config debug should just work and pick up the current environment in the terminal window.

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 11, 2025
@karthiknadig
Copy link
Member

Duplicate of #606

Closing against #606 that has more details on the root cause.

@taldcroft taldcroft changed the title No-config debug uses default system Python, not the active Python in terminal No-config debug uses default system Python on MacOS, not the active Python in terminal Feb 14, 2025
@eleanorjboyd
Copy link
Member

re-open because OS type is different. Thanks for pointing it out @taldcroft !

@eleanorjboyd eleanorjboyd reopened this Feb 14, 2025
@karthiknadig
Copy link
Member

@taldcroft Can you share the python binary names in the env you have? does it have python3 ?

@taldcroft
Copy link
Author

@karthiknadig - here you go:

(ska3-flight-2025.0rc2) ➜  ~ which python                                                           
/Users/aldcroft/miniconda3-arm/envs/ska3-flight-2025.0rc2/bin/python
(ska3-flight-2025.0rc2) ➜  ~ cd /Users/aldcroft/miniconda3-arm/envs/ska3-flight-2025.0rc2/bin/       
(ska3-flight-2025.0rc2) ➜  ls -l python*
lrwxr-xr-x  1 aldcroft  staff       10 Jan  3 14:13 python@ -> python3.12
lrwxr-xr-x  1 aldcroft  staff       10 Jan  3 14:13 python3@ -> python3.12
lrwxr-xr-x  1 aldcroft  staff       17 Jan  3 14:13 python3-config@ -> python3.12-config
lrwxr-xr-x  1 aldcroft  staff       10 Jan  3 14:13 python3.1@ -> python3.12
-rwxr-xr-x  1 aldcroft  staff  6576272 Jan  3 14:13 python3.12*
-rwxr-xr-x  1 aldcroft  staff     2091 Jan  3 14:13 python3.12-config*```

@eleanorjboyd
Copy link
Member

what is your shell type for your terminal?

@taldcroft
Copy link
Author

what is your shell type for your terminal?

zsh.

@eleanorjboyd
Copy link
Member

Hi! Sorry for the delay, I am bit stuck and not sure what is going wrong here. Does updating the extension help? This is the shell script we are trying to run, what happens if you run this?

#! /bin/bash
# Bash script
export DEBUGPY_ADAPTER_ENDPOINTS=$VSCODE_DEBUGPY_ADAPTER_ENDPOINTS
python3 $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $@

@taldcroft
Copy link
Author

I think the extension was up to date, but just to be sure I restarted VS code to get the latest bug-fix release. The debugpy behavior is now even more unexpected. When I run those lines above, or debugpy go.py, it changes my application focus to a different VS code window, with the following:

Image

In fact at that point all 5 of my active VS code windows are showing that popup.

@eleanorjboyd
Copy link
Member

Can you confirm by sending the version for the python-debugger extension? This is a similar error message to the one I fixed with version 2025.0.1. Secondly are you running any other debuggers in the other windows? No config debugging doesn't work with parallel or multiple runs so I wanted to check

@taldcroft
Copy link
Author

Identifier ms-python.debugpy
Version 2025.1.2025022401
Last Updated 2025-02-24, 08:40:06

If I type debugpy --version I get 1.8.12.

Secondly are you running any other debuggers in the other windows? No config debugging doesn't work with parallel or multiple runs so I wanted to check.

No.

@karthiknadig
Copy link
Member

@taldcroft Do you have the following in your user settings.json?

"python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]

Can you share what you have for PATH env variable in the terminal where it does not work?

> echo $PATH
> whereis python

@taldcroft
Copy link
Author

@taldcroft Do you have the following in your user settings.json?

"python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]

No. I have these terminal settings:

➜  grep -i terminal ~/Library/Application\ Support/Code/User/settings.json
    "terminal.integrated.inheritEnv": false,
    "terminal.integrated.fontSize": 14,
    "terminal.integrated.defaultProfile.osx": "zsh",
    "githubPullRequests.terminalLinksHandler": "github",
    "python.terminal.activateEnvironment": false,
    "terminal.integrated.enableMultiLinePasteWarning": "never",
    "terminal.integrated.scrollback": 5000,

I tried using "terminal.integrated.inheritEnv": true but this made no difference.

Can you share what you have for PATH env variable in the terminal where it does not work?

> echo $PATH
> whereis python
➜  echo $PATH
/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/texbin:/Users/aldcroft/miniconda3-arm/condabin:/Users/aldcroft/.cargo/bin:/Users/aldcroft/.vscode/extensions/ms-python.debugpy-2025.1.2025022401-darwin-arm64/bundled/scripts/noConfigScripts:/Users/aldcroft/Library/Application Support/Code/User/globalStorage/github.copilot-chat/debugCommand
➜  whereis python
python:
➜  which python
python not found

@eleanorjboyd
Copy link
Member

so to clarify in your shell python doesn't alias to anything? like with which python or whereis python? What about the same but instead with python3? This is the script we attempt to run when you call no config debugging so if the python3 in your terminal aliases to the global one then that might be your problem?

#! /bin/bash
# Bash script
export DEBUGPY_ADAPTER_ENDPOINTS=$VSCODE_DEBUGPY_ADAPTER_ENDPOINTS
python3 $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $@

@taldcroft
Copy link
Author

taldcroft commented Mar 4, 2025

Since I opened this issue the behavior has changed. The path reported in my script is now correct:

(base) ➜  which python
/Users/aldcroft/miniconda3-arm/bin/python
(base) ➜  which python3
/Users/aldcroft/miniconda3-arm/bin/python3
(base) ➜  grep python ~/.bash_profile
(base) ➜  grep python ~/.zshrc       
(base) ➜  cat go.py
import sys
print(sys.prefix)
(base) ➜  debugpy go.py
/Users/aldcroft/miniconda3-arm

HOWEVER, there is a new problem which I described a few days ago: #605 (comment)

To reiterate, when I run debugpy go.py in one VScode window, then the debugger is started in all 5 of my open VScode windows:

  • 4 of them show a popup that the server is already being debugged.
  • One of them successfully starts and runs the debugger
  • This is NOT the one containing the terminal where I ran debugpy go.py.

@eleanorjboyd
Copy link
Member

thank you for clarifying, sorry about that. In relation to your new problem, are all the vscode windows open on the same folder / workspace or on different ones?

@taldcroft
Copy link
Author

thank you for clarifying, sorry about that. In relation to your new problem, are all the vscode windows open on the same folder / workspace or on different ones?

All different.

@eleanorjboyd
Copy link
Member

will try and repro myself- thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants