vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.43k stars 237 forks source link

Bundled Python interpreter not being used in debugger #909

Open savvn001 opened 1 year ago

savvn001 commented 1 year ago

OS: macOS 13.3, M1 MBA VSCode version:
Version: 1.77.2 (Universal) Commit: e344f1f539a80912a0e9357cec841f36ce97a4e2 Date: 2023-04-06T10:12:31.126Z (6 days ago) Electron: 19.1.11 Chromium: 102.0.5005.196 Node.js: 16.14.2 V8: 10.2.154.26-electron.0 OS: Darwin arm64 22.4.0 Sandboxed: No CodeLLDB version: v1.9.0 Compiler: clang

Hi, I had a debug configuration using this extension where a Python script was loaded on init. This was added to the debug config:

"initCommands": [
   "command script import path_to_my_python_script.py" 
]

The script imports numpy, now the issue is, I'm getting a ModuleNotFoundError: No module named 'numpy' when I start the debugger. Previously this was all working fine because I'd gone to "LLDB Command Prompt" and installed the package. I did the "LLDB Command Prompt" command again and did pip list. It seems the package numpy and others I installed are still there, great. But why can't the debugger find it on launch? If I comment out the initCommands, and start the debugger, i tried to find what interpreter it had loaded by using these commands:

?/py os.__file__
"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/os.py"
?/py print(sys.executable)
/Users/myself/.vscode/extensions/vadimcn.vscode-lldb-1.9.0/adapter/codelldb

If I go back to "LLDB Command Prompt" and do the same commands:

(lldb) script sys.executable
'/Users/myself/.vscode/extensions/vadimcn.vscode-lldb-1.9.0/lldb/bin/lldb'
(lldb) script os.__file__
'/Users/myself/.vscode/extensions/vadimcn.vscode-lldb-1.9.0/lldb/lib/python3.9/os.py'

So I'm not sure what's going on here. It looks like when the debugger is started, it's not using the same python interpreter as when I do "LLDB Command Prompt" because otherwise it would have the numpy package installed. Can this be overridden somehow?

vadimcn commented 1 year ago

By design: https://github.com/vadimcn/codelldb/blob/master/MANUAL.md#installing-packages

savvn001 commented 1 year ago

Hi, sorry but I may be mis understanding. Why is another python interpreter being used when I start the debugger vs when I run the LLDB: Command Prompt command in VSCode? Is that by design?

vadimcn commented 1 year ago

Ah, sorry, misread the report. The debugger should be using the bundled Python, but I guess system Python somehow managed to take precedence. (Did macos recently upgrade to Python 3.9?)

savvn001 commented 1 year ago

Ah might that be it? That Python3.9 that is being used, looks like some system Python that was installed recently, I've been doing some xcode development recently and I think it was created around that time. Does this extension look for some environment variable or something when the debugger starts?

Could that be overridden with some flags on init as a quick workaround?

vadimcn commented 1 year ago

Try 'pip install --user numpy'. In this case it shouldn't matter which Python gets used.

savvn001 commented 1 year ago

Doesn't solve the issue unfourtunately. If I go to LLDB: Command Prompt command and do:

(lldb) pip list --user
Package             Version
------------------- -------
contourpy           1.0.7
cycler              0.11.0
fonttools           4.39.3
importlib-resources 5.12.0
kiwisolver          1.4.4
matplotlib          3.7.1
numpy               1.23.5
packaging           23.0
pandas              1.5.1
Pillow              9.5.0
plotly              5.11.0
pyparsing           3.0.9
python-dateutil     2.8.2
pytz                2022.6
six                 1.16.0
tenacity            8.1.0
zipp                3.15.0

I can see all my needed packages are installed. If I do 'pip install --user numpy'. It will say requirements already satisfied.