diff --git a/src/debugpy/server/api.py b/src/debugpy/server/api.py index 82bd8618d..a92fea4d3 100644 --- a/src/debugpy/server/api.py +++ b/src/debugpy/server/api.py @@ -23,6 +23,7 @@ "qt": "none", "subProcess": True, "python": sys.executable, + "pythonEnv": {}, } _config_valid_values = { @@ -188,6 +189,12 @@ def listen(address, settrace_kwargs): creationflags |= 0x08000000 # CREATE_NO_WINDOW creationflags |= 0x00000200 # CREATE_NEW_PROCESS_GROUP + # On embedded applications, environment variables might not contain + # Python environment settings. + python_env = _config.get("pythonEnv") + if not bool(python_env): + python_env = None + # Adapter will outlive this process, so we shouldn't wait for it. However, we # need to ensure that the Popen instance for it doesn't get garbage-collected # by holding a reference to it in a non-local variable, to avoid triggering @@ -195,7 +202,7 @@ def listen(address, settrace_kwargs): try: global _adapter_process _adapter_process = subprocess.Popen( - adapter_args, close_fds=True, creationflags=creationflags + adapter_args, close_fds=True, creationflags=creationflags, env=python_env ) if os.name == "posix": # It's going to fork again to daemonize, so we need to wait on it to