For Python debugging to work, a specific Python toolchain MUST be set #4745
Labels
awaiting-maintainer
Awaiting review from Bazel team on issues
lang: python
Python rules integration
product: CLion
CLion plugin
product: IntelliJ
IntelliJ plugin
type: bug
Description of the bug:
I spent several frustrating hours on this, so I just want to leave a note for others. I was unable to find anything else on the internet. #2093 is not the same thing.
For those looking for the fix
Python code debugging does not work if you rely on the Bazel to autodetect the Python toolchain installed on your system!. This assumes you are using rules_python. At the minimum, you must explicitly specify a non-portable, non-hermetic, system toolchain like so. Obviously, it is recommended to create a better toolchain for production use cases (example):
If you only care about the fix, you can stop reading here.
The root cause is the various shims that interpose and create child processes. By default, a
py_binary
orpy_test
target's actual executable file is this wrapper. Without a toolchain,PYTHON_BINARY
is set topy3wrapper.sh
, a shell script. Even when pydevd is launched by the IDE in multiprocess mode, on every process launch, it tries to determine if the new process is a Python process. If the name isn'tpython
or similar, it then looks for a shebang line to be python, which also fails in this case. So it never attaches topy3wrapper.sh
or any subprocesses created by it (so the actual running program).I had to resort to modifying the included copy of
pydevd
in the IDE (Python plugin) to switch it to debug mode and figure this out.What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
greeting()
orfoo()
.After adding a toolchain
Which Intellij IDE are you using? Please provide the specific version.
Tested on CLion 2023.1, IntelliJ IDEA 2023.1 (Community Edition) Build #IC-231.8109.175
What programming languages and tools are you using? Please provide specific versions.
Bazel 6.0.0
What Bazel plugin version are you using?
Development tip 9a7b789
Have you found anything relevant by searching the web?
No
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: