Skip to content
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

Python env resolver ignores user specified interpreter #24767

Open
dta-bdai opened this issue Jan 31, 2025 · 2 comments
Open

Python env resolver ignores user specified interpreter #24767

dta-bdai opened this issue Jan 31, 2025 · 2 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster needs spike Label for issues that need investigation before they can be worked on.

Comments

@dta-bdai
Copy link

Type: Bug

We have a wrapper around a Bazel generated script that launches the Python interpreter inside Bazel with all environment variables and Python paths setup properly, pointing to the correct locations of Python packages and dependencies inside Bazel runfiles dir. The technique is similar to this: https://sransara.com/notes/2023/bazel-python-venv/

We point VSCode Python interpreter to the wrapper script, and it used to work well.

Since version 2024.18.0, this workflow does not work anymore. Python extension ignores the wrapper we specified and automatically finds and switches to the bare python interpreter in the script runfiles dir, which doesn't have any path setup.

Is there a way to revive the old mechanism, i.e. forcing VSCode to respect the user-specified Python interpreter path?

Extension version: 2024.22.2
VS Code version: Code 1.96.2 (fabdb6a30b49f79a7aba0f2ad9df9b399473380f, 2024-12-19T10:22:47.216Z)
OS version: Linux x64 6.8.0-51-generic
Modes:
Remote OS version: Linux x64 6.8.0-1017-gcp

  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.15
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Unknown
  • Value of the python.languageServer setting: Pylance
User Settings


languageServer: "Pylance"

Installed Extensions
Extension Name Extension Id Version
Bazel BazelBuild.vscode-bazel 0.11.0
Black Formatter ms-python.black-formatter 2024.4.0
GitHub Pull Requests GitHub.vscode-pull-request-github 0.102.0
Image Manager Minko.image-manager 2.3.13
Image Viewer vscode-infra.image-viewer 1.6.5
JavaScript Debugger ms-vscode.js-debug 1.96.0
Jupyter ms-toolsai.jupyter 2024.11.0
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.21
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Pylance ms-python.vscode-pylance 2024.12.1
Python ms-python.python 2024.22.2
Python Debugger ms-python.debugpy 2024.14.0
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.10
System Info
Item Value
CPUs 13th Gen Intel(R) Core(TM) i7-1365U (12 x 1360)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
webnn: disabled_off
Load (avg) 1, 1, 1
Memory (System) 31.00GB (16.96GB free)
Process Argv --crash-reporter-id ec7e8904-7db5-4f73-ba38-b9376943463d
Screen Reader no
VM 0%
DESKTOP_SESSION ubuntu
XDG_CURRENT_DESKTOP Unity
XDG_SESSION_DESKTOP ubuntu
XDG_SESSION_TYPE x11
Item Value
Remote Container ghcr.io/bdaiinstitute/dmm_amd64:main (starfish-develop) @ vm2-local
OS Linux x64 6.8.0-1017-gcp
CPUs Intel(R) Xeon(R) CPU @ 2.30GHz (32 x 0)
Memory (System) 117.91GB (108.33GB free)
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt551cf:31179979
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
vscaac:30438847
c4g48928:30535728
azure-dev_surveyonecf:30548226
vscrpc:30673769
a9j8j154:30646983
962ge761:30959799
pythonnoceb:30805159
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupyter:31046869
nativerepl2:31139839
pythonrstrctxt:31112756
nativeloc2:31192216
iacca1:31171482
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624
dwoutputs:31217127
hdaa2157:31222309
copilot_t_ci:31222730

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

@dta-bdai Can you share the logs with the broken case? share the Output > Python, and Output> Python Locator logs.

The work around is to use python.locator to js. But note that it is our old locator, it is getting replaced with native locator. So the logs you provide will be help full in make sure this is supported.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Feb 3, 2025
@karthiknadig karthiknadig self-assigned this Feb 3, 2025
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug needs spike Label for issues that need investigation before they can be worked on. and removed triage-needed Needs assignment to the proper sub-team labels Feb 3, 2025
@dta-bdai
Copy link
Author

dta-bdai commented Feb 3, 2025

Thanks! Confirmed that js locator doesn't suffer from this problem.

Here are the logs for the native locator:

Output > Python:

2025-02-03 22:34:27.549 [debug] Interpreter Path updated attached-container_WORKSPACE_FOLDER_INTERPRETER_PATH_/home/dta/starfish /home/dta/starfish/bazel-bin/my_python
2025-02-03 22:34:27.552 [debug] Testing: Triggered refresh due to interpreter change.
2025-02-03 22:34:27.552 [debug] Testing: Clearing all discovered tests
2025-02-03 22:34:27.552 [debug] Testing: Forcing test data refresh
2025-02-03 22:34:27.552 [debug] Testing: Refreshing all test data
2025-02-03 22:34:27.587 [debug] Extension ms-python.vscode-pylance accessed getActiveEnvironmentPath with args: undefined
2025-02-03 22:34:27.588 [debug] Python API env change detected /home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python add
2025-02-03 22:34:27.589 [info] Discover tests for workspace name: starfish - uri: /home/dta/starfish
2025-02-03 22:34:27.590 [info] Python interpreter path: ./bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python
2025-02-03 22:34:27.595 [debug] could not find a pixi interpreter for the interpreter at /home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python
2025-02-03 22:34:27.600 [debug] Extension ms-python.vscode-pylance accessed resolveEnvironment with args: {"id":"/home/dta/starfish/bazel-bin/my_python","path":"/home/dta/starfish/bazel-bin/my_python"}
2025-02-03 22:34:27.666 [debug] Extension ms-python.vscode-pylance accessed getActiveEnvironmentPath with args: undefined
2025-02-03 22:34:27.667 [debug] Extension ms-python.vscode-pylance accessed getEnvironmentVariables with args: undefined
2025-02-03 22:34:27.667 [debug] Extension ms-python.vscode-pylance accessed resolveEnvironment with args: {"id":"/home/dta/starfish/bazel-bin/my_python","path":"/home/dta/starfish/bazel-bin/my_python"}
2025-02-03 22:34:27.703 [debug] Activation Commands received undefined for shell /usr/bin/bash, resource /home/dta/starfish and interpreter /home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python
2025-02-03 22:34:27.704 [debug] Activated environment variables for /home/dta/starfish undefined

Output > Python Locator:

2025-02-03 22:34:27.560 [debug] Resolving env "/home/dta/starfish/bazel-bin/my_python"
2025-02-03 22:34:27.562 [debug] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
2025-02-03 22:34:27.562 [debug] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
2025-02-03 22:34:27.582 [info] Env ("/home/dta/starfish/bazel-bin/my_python") in Path resolved as ResolvedPythonEnv { executable: "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python3", prefix: "/home/dta/.cache/bazel/_bazel_dta/8c493c99c7acff6adb3677a40a7c7316/external/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu", version: "3.10.16.final.0", is64_bit: true, symlinks: Some(["/home/dta/starfish/bazel-bin/my_python", "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python3"]) } and reported as None
2025-02-03 22:34:27.583 [debug] In resolve_environment, Resolved Python Exe "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python" as ResolvedPythonEnv { executable: "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python", prefix: "/home/dta/.cache/bazel/_bazel_dta/8c493c99c7acff6adb3677a40a7c7316/external/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu", version: "3.10.16.final.0", is64_bit: true, symlinks: Some(["/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python", "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python3", "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python3.10"]) }
2025-02-03 22:34:27.583 [debug] Using cache from "/home/dta/.vscode-server/data/User/globalStorage/ms-python.python/pythonLocator/8f3db1484a42f72e.3.json" for "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python"
2025-02-03 22:34:27.585 [debug] Updating cache for "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python" with new symlinks
2025-02-03 22:34:27.586 [debug] Caching interpreter info for "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python"
2025-02-03 22:34:27.586 [debug] Caching "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python" in "/home/dta/.vscode-server/data/User/globalStorage/ms-python.python/pythonLocator/8f3db1484a42f72e.3.json"
2025-02-03 22:34:27.586 [debug] Resolved env (Ok(32.54288ms)) "/home/dta/starfish/bazel-bin/my_python" as PythonEnvironment { display_name: None, name: None, executable: Some("/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python"), kind: None, version: Some("3.10.16.final.0"), prefix: Some("/home/dta/.cache/bazel/_bazel_dta/8c493c99c7acff6adb3677a40a7c7316/external/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu"), manager: None, project: None, arch: Some(X64), symlinks: Some(["/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python", "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python3", "/home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python3.10"]) }
2025-02-03 22:34:27.587 [info] Resolved Python Environment /home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python

The path I chose is /home/dta/starfish/bazel-bin/my_python, and it's automatically resolved to /home/dta/starfish/bazel-bin/my_python.runfiles/rules_python~~python~python_3_10_x86_64-unknown-linux-gnu/bin/python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster needs spike Label for issues that need investigation before they can be worked on.
Projects
None yet
Development

No branches or pull requests

2 participants