Repository: rust
Issue: Debuginfo tests sometimes run with the wrong Python version on MacOS
Labels: A-testsuite,O-macos,A-debuginfo,T-bootstrap,C-bug

Running `./x t tests/debuginfo` on my system configuration creates a lot of errors like this:

```
---- [debuginfo-lldb] tests/debuginfo/basic-types.rs stdout ----
NOTE: compiletest thinks it is using LLDB version 1700
NOTE: compiletest thinks it is using LLDB without native rust support
error: Error while running LLDB
status: exit status: 1
command: PYTHONPATH="/opt/homebrew/Cellar/llvm/17.0.6_1/libexec/python3.12/site-packages" PYTHONUNBUFFERED="1" "/usr/bin/python3" "/Users/user/Documents/projects/rust/src/etc/lldb_batchmode.py" "/Users/user/Documents/projects/rust/build/aarch64-apple-darwin/test/debuginfo/basic-types.lldb/a" "/Users/user/Documents/projects/rust/build/aarch64-apple-darwin/test/debuginfo/basic-types.lldb/basic-types.debugger.script"
--- stdout -------------------------------
3.9.6 (default, Feb  3 2024, 15:58:27)
[Clang 15.0.0 (clang-1500.3.9.4)]
------------------------------------------
--- stderr -------------------------------
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/llvm/17.0.6_1/libexec/python3.12/site-packages/lldb/__init__.py", line 44, in <module>
    import _lldb
ModuleNotFoundError: No module named '_lldb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Documents/projects/rust/src/etc/lldb_batchmode.py", line 17, in <module>
    import lldb
  File "/opt/homebrew/Cellar/llvm/17.0.6_1/libexec/python3.12/site-packages/lldb/__init__.py", line 47, in <module>
    from . import _lldb
ImportError: cannot import name '_lldb' from partially initialized module 'lldb' (most likely due to a circular import) (/opt/homebrew/Cellar/llvm/17.0.6_1/libexec/python3.12/site-packages/lldb/__init__.py)
------------------------------------------
```

I have the following system configuration:

```
$ which lldb
/opt/homebrew/opt/llvm/bin/lldb
$ /opt/homebrew/opt/llvm/bin/lldb --version
3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
lldb version 17.0.6
$ xcrun -f lldb
/Library/Developer/CommandLineTools/usr/bin/lldb
$ /Library/Developer/CommandLineTools/usr/bin/lldb --version
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
$ which python3
/opt/homebrew/bin/python3
$ /opt/homebrew/bin/python3 --version
Python 3.12.2
$ xcrun -f python3
/Library/Developer/CommandLineTools/usr/bin/python3
$ /Library/Developer/CommandLineTools/usr/bin/python3 --version
Python 3.9.6
$ printenv | grep PYTHON
# nothing
```

Homebrew provides the default python3 and lldb in `PATH`, with python 3.12.2. There is also the CLI tools versions, which are available via `xcrun` or at `/usr/bin`, with python version 3.9.6. This should be a pretty common configuration.

`_lldb.cpython-312-darwin.so` exists in `/opt/homebrew/Cellar/llvm/17.0.6_1/libexec/python3.12/site-packages/lldb/`, but based on some poking around it seems like this is trying to get run with python 3.9. This makes me think that `lldb_python_dir` in `compiletest` is not choosing a version that aligns with the LLDB version/path imported by `src/etc/lldb_batchmode.py`.

Some discussion at https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/.E2.9C.94.20MacOS.20_lldb.20python.20error.20for.20debugifo.20tests

@rustbot label +A-testsuite +O-macos +T-bootstrap