microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.32k stars 1.18k forks source link

Python 3.1x from Conda environment sometimes detected as 3.1 #23649

Closed maresb closed 4 months ago

maresb commented 4 months ago

Type: Bug

Behaviour

When the Python extension loads, it often detects Python 3.11 as Python 3.1.

As originally reported by @niemiaszek in https://github.com/microsoft/vscode-python/pull/22968#issuecomment-2178915891,

One strange thing for me is the fact that VS Code detects python 3.1.x in Select Interpreter context. Is that some bug related to current version of VS Code or Pixi? Could it have some implications on integration with other VS Code extensions like Ruff?

My suspicion is that this has to do with the symlink python3.1 -> python3.1X present in Conda environments.

Here's what I see:

image

image

And here's my Jupyter log output, which doesn't seem particularly informative:

Visual Studio Code (1.90.1, dev-container, desktop)
Jupyter Extension Version: 2024.5.0.
Python Extension not installed.
Pylance Extension not installed.
Platform: linux (x64).
Workspace folder /workspaces/projectname, Home = /home/mambauser
09:45:12.525 [info] Starting Kernel (Python Path: /opt/conda/bin/python, Conda, 3.11.undefined) for '/workspaces/projectname/Untitled-3.ipynb' (disableUI=true)
09:45:15.783 [info] Process Execution: /opt/conda/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
09:45:15.800 [info] Process Execution: /opt/conda/bin/python -m ipykernel_launcher --f=/home/~/.local/share/jupyter/runtime/kernel-v2-416foZ3dcdQ2w4v.json
    > cwd: //workspaces/projectname
09:45:15.837 [info] Process Execution: /opt/conda/bin/python -m pip list
09:45:17.364 [info] Kernel successfully started

What really tipped me off was the output from the Ruff extension since their logs are very targeted:

2024-06-20 07:48:37.054 [info] Name: Ruff
2024-06-20 07:48:37.054 [info] Module: ruff
2024-06-20 07:48:37.054 [error] Python version 3.1 is not supported.
2024-06-20 07:48:37.054 [error] Selected python path: /opt/conda/bin/python
2024-06-20 07:48:37.054 [error] Supported versions are 3.7 and above.
2024-06-20 07:48:37.054 [error] Python version 3.1 is not supported.
2024-06-20 07:48:37.054 [error] Selected python path: /opt/conda/bin/python
2024-06-20 07:48:37.054 [error] Supported versions are 3.7 and above.
2024-06-20 07:48:37.054 [error] Python interpreter missing:
[Option 1] Select Python interpreter using the ms-python.python.
[Option 2] Set an interpreter using "ruff.interpreter" setting.
Please use Python 3.7 or greater.
EXPAND FOR PYTHON LOG EXCERPTS I have to be really careful here about leaking sensitive info since these logs include full environment variable dumps. ``` ... 2024-06-20 07:45:12.407 [debug] Probing conda binary: conda 2024-06-20 07:45:12.446 [info] > conda info --json 2024-06-20 07:45:12.524 [debug] No cached env found for /opt/conda/bin/python 2024-06-20 07:45:12.558 [debug] No cached env found for /opt/conda/bin/python 2024-06-20 07:45:12.593 [debug] Extension ms-toolsai.jupyter accessed resolveEnvironment with args: "/opt/conda/bin/python" 2024-06-20 07:45:12.602 [debug] No cached env found for /opt/conda/bin/python 2024-06-20 07:45:12.602 [debug] No cached env found for /opt/conda/bin/python 2024-06-20 07:45:12.706 [debug] Extension ms-toolsai.jupyter accessed resolveEnvironment with args: {"internal":{"path":"/opt/conda/bin/python","id":"/opt/conda/bin/python","executable":{"uri":{"$mid":1,"fsPath":"/opt/conda/bin/python","external":"file:///opt/conda/bin/python","path":"/opt/conda/bin/python","scheme":"file"},"bitness":"Unknown","sysPrefix":"/opt/conda"},"environment":{"type":"Conda","name":"base","folderUri":{"$mid":1,"path":"/opt/conda","scheme":"file"}},"version":{"major":3,"minor":11},"tools":["Conda"]},"id":"/opt/conda/bin/python"} 2024-06-20 07:45:12.707 [debug] Extension ms-toolsai.jupyter accessed resolveEnvironment with args: {"internal":{"path":"/opt/conda/bin/python","id":"/opt/conda/bin/python","executable":{"uri":{"$mid":1,"fsPath":"/opt/conda/bin/python","external":"file:///opt/conda/bin/python","path":"/opt/conda/bin/python","scheme":"file"},"bitness":"Unknown","sysPrefix":"/opt/conda"},"environment":{"type":"Conda","name":"base","folderUri":{"$mid":1,"path":"/opt/conda","scheme":"file"}},"version":{"major":3,"minor":11},"tools":["Conda"]},"id":"/opt/conda/bin/python"} 2024-06-20 07:45:12.710 [debug] Extension ms-toolsai.jupyter accessed onDidEnvironmentVariablesChange with args: undefined 2024-06-20 07:45:12.711 [debug] Extension ms-toolsai.jupyter accessed getEnvironmentVariables with args: undefined 2024-06-20 07:45:12.712 [debug] Extension ms-toolsai.jupyter accessed resolveEnvironment with args: {"internal":{"path":"/opt/conda/bin/python","id":"/opt/conda/bin/python","executable":{"uri":{"$mid":1,"fsPath":"/opt/conda/bin/python","external":"file:///opt/conda/bin/python","path":"/opt/conda/bin/python","scheme":"file"},"bitness":"Unknown","sysPrefix":"/opt/conda"},"environment":{"type":"Conda","name":"base","folderUri":{"$mid":1,"path":"/opt/conda","scheme":"file"}},"version":{"major":3,"minor":11},"tools":["Conda"]},"id":"/opt/conda/bin/python"} 2024-06-20 07:45:12.713 [debug] Extension ms-toolsai.jupyter accessed resolveEnvironment with args: {"internal":{"path":"/opt/conda/bin/python","id":"/opt/conda/bin/python","executable":{"uri":{"$mid":1,"fsPath":"/opt/conda/bin/python","external":"file:///opt/conda/bin/python","path":"/opt/conda/bin/python","scheme":"file"},"bitness":"Unknown","sysPrefix":"/opt/conda"},"environment":{"type":"Conda","name":"base","folderUri":{"$mid":1,"path":"/opt/conda","scheme":"file"}},"version":{"major":3,"minor":11},"tools":["Conda"]},"id":"/opt/conda/bin/python"} ... 2024-06-20 07:45:13.689 [debug] Received shell integration sequence for bash 2024-06-20 07:45:13.723 [debug] Found hatch binary hatch 2024-06-20 07:45:13.724 [debug] Finished searching for Hatch envs 2024-06-20 07:45:14.236 [debug] conda info --json: { "GID": 1000, "UID": 1000, "active_prefix": "/opt/conda", "active_prefix_name": "base", "av_data_dir": "/opt/conda/etc/conda", "av_metadata_url_base": null, "channels": [ "https://conda.anaconda.org/conda-forge/linux-64", "https://conda.anaconda.org/conda-forge/noarch" ], "conda_build_version": "not installed", "conda_env_version": "24.5.0", "conda_location": "/opt/conda/lib/python3.11/site-packages/conda", "conda_prefix": "/opt/conda", "conda_shlvl": 1, "conda_version": "24.5.0", "config_files": [ "/home/mambauser/.condarc" ], "default_prefix": "/opt/conda", "env_vars": { "CIO_TEST": "", "CONDA_DEFAULT_ENV": "base", "CONDA_EXE": "/opt/conda/bin/conda", "CONDA_PREFIX": "/opt/conda", "CONDA_PROMPT_MODIFIER": "(base) ", "CONDA_PYTHON_EXE": "/opt/conda/bin/python", "CONDA_ROOT": "/opt/conda", "CONDA_SHLVL": "1", "CURL_CA_BUNDLE": "", "GDAL_DRIVER_PATH": "/opt/conda/lib/gdalplugins", "LD_PRELOAD": "", "PATH": "/vscode/vscode-server/bin/linux-x64/611f9bfce64f25108829dd295f54a6894e87339d/bin/remote-cli:/home/mambauser/.local/bin:/opt/conda/bin:/opt/conda/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/mambauser/.local/bin", "PYTHONIOENCODING": "utf-8", "PYTHONUNBUFFERED": "1", "REQUESTS_CA_BUNDLE": "", "SSL_CERT_FILE": "" }, "envs": [ "/opt/conda" ], "envs_dirs": [ "/opt/conda/envs", "/home/mambauser/.conda/envs" ], "netrc_file": null, "offline": false, "pkgs_dirs": [ "/opt/conda/pkgs", "/home/mambauser/.conda/pkgs" ], "platform": "linux-64", "python_version": "3.11.9.final.0", "rc_path": "/home/mambauser/.condarc", "requests_version": "2.32.3", "root_prefix": "/opt/conda", "root_writable": true, "site_dirs": [], "solver": { "default": true, "name": "libmamba", "user_agent": "solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.8" }, "sys.executable": "/opt/conda/bin/python", "sys.prefix": "/opt/conda", "sys.version": "3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:36:13) [GCC 12.3.0]", "sys_rc_path": "/opt/conda/.condarc", "user_agent": "conda/24.5.0 requests/2.32.3 CPython/3.11.9 Linux/5.15.0-107-generic ubuntu/22.04.4 glibc/2.35 solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.8", "user_rc_path": "/home/mambauser/.condarc", "virtual_pkgs": [ [ "__archspec", "1", "skylake" ], [ "__conda", "24.5.0", "0" ], [ "__glibc", "2.35", "0" ], [ "__linux", "5.15.0", "0" ], [ "__unix", "0", "0" ] ] } 2024-06-20 07:45:14.236 [debug] Found conda via filesystem probing: conda 2024-06-20 07:45:14.255 [debug] Best effort version B for /opt/conda/bin/python {"major":3,"minor":1,"micro":-1} 2024-06-20 07:45:14.259 [debug] Best effort version B for /opt/conda/bin/python {"major":3,"minor":1,"micro":-1} 2024-06-20 07:45:14.263 [debug] Best effort version B for /opt/conda/bin/python {"major":3,"minor":1,"micro":-1} 2024-06-20 07:45:14.265 [debug] Best effort version B for /opt/conda/bin/python {"major":3,"minor":1,"micro":-1} 2024-06-20 07:45:14.268 [debug] Best effort version B for /opt/conda/bin/python {"major":3,"minor":1,"micro":-1} 2024-06-20 07:45:14.270 [debug] Best effort version B for /opt/conda/bin/python {"major":3,"minor":1,"micro":-1} 2024-06-20 07:45:14.277 [debug] Best effort version B for /opt/conda/bin/python {"major":3,"minor":1,"micro":-1} 2024-06-20 07:45:14.278 [debug] Best effort version C for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.278 [debug] Best effort version C for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.279 [debug] Best effort version C for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.279 [debug] Best effort version C for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.279 [debug] Best effort version C for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.279 [debug] Best effort version C for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.279 [debug] Best effort version C for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.283 [debug] Best effort version D for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.285 [debug] Best effort version D for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.285 [debug] Best effort version D for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.286 [debug] Best effort version D for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.287 [debug] Best effort version D for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.288 [debug] Best effort version D for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.289 [debug] Best effort version D for /opt/conda/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}} 2024-06-20 07:45:14.292 [info] Environments refresh finished (event): 3074 milliseconds 2024-06-20 07:45:14.292 [debug] Finished with environment resolver 2024-06-20 07:45:14.292 [debug] Finished with environment reducer 2024-06-20 07:45:14.292 [info] Environments refresh paths discovered: 3074 milliseconds 2024-06-20 07:45:14.293 [debug] Environment resolver resolved /opt/conda/bin/python for {"name":"base","location":"/opt/conda","kind":"virt-conda","executable":{"filename":"/opt/conda/bin/python","sysPrefix":"","ctime":1718314262335,"mtime":1718314262335},"display":"Python 3.1.x ('base')","version":{"major":3,"minor":1,"micro":-1},"arch":1,"distro":{"org":"Anaconda, Inc."},"source":[],"type":"Conda","id":"/opt/conda/bin/python","detailedDisplayName":"Python 3.1.x ('base': conda)"} to {"arch":1,"executable":{"filename":"/opt/conda/bin/python","ctime":-1,"mtime":-1,"sysPrefix":"/opt/conda"},"version":{"major":3,"minor":1,"micro":-1}} 2024-06-20 07:45:14.295 [debug] Resolved /opt/conda/bin/python using downstream locator 2024-06-20 07:45:14.295 [debug] Python API env change detected /opt/conda/bin/python update 2024-06-20 07:45:14.295 [debug] Flushing env to cache /opt/conda/bin/python 2024-06-20 07:45:14.296 [info] Python interpreter path: /opt/conda/bin/python 2024-06-20 07:45:14.297 [debug] Found cached env for /opt/conda/bin/python 2024-06-20 07:45:14.297 [debug] Environment resolver resolved /opt/conda/bin/python for {"name":"base","location":"/opt/conda","kind":"virt-conda","executable":{"filename":"/opt/conda/bin/python","sysPrefix":"","ctime":1718314262335,"mtime":1718314262335},"display":"Python 3.1.x ('base')","version":{"major":3,"minor":1,"micro":-1},"arch":1,"distro":{"org":"Anaconda, Inc."},"source":[],"type":"Conda","id":"/opt/conda/bin/python","detailedDisplayName":"Python 3.1.x ('base': conda)"} to {"arch":1,"executable":{"filename":"/opt/conda/bin/python","ctime":-1,"mtime":-1,"sysPrefix":"/opt/conda"},"version":{"major":3,"minor":1,"micro":-1}} 2024-06-20 07:45:14.297 [debug] Resolved /opt/conda/bin/python using downstream locator 2024-06-20 07:45:14.297 [debug] Flushing env to cache /opt/conda/bin/python 2024-06-20 07:45:14.298 [error] Invalid version for /opt/conda/bin/python: {"name":"base","location":"/opt/conda","kind":"virt-conda","executable":{"filename":"/opt/conda/bin/python","sysPrefix":"/opt/conda","ctime":1718314262335,"mtime":1718314262335},"display":"Python 3.1.x ('base')","version":{"major":3,"minor":1,"micro":-1},"arch":1,"distro":{"org":"Anaconda, Inc."},"source":[],"type":"Conda","id":"/opt/conda/bin/python","detailedDisplayName":"Python 3.1.x ('base': conda)"} 2024-06-20 07:45:14.298 [debug] Environment resolver resolved /opt/conda/bin/python for {"name":"base","location":"/opt/conda","kind":"virt-conda","executable":{"filename":"/opt/conda/bin/python","sysPrefix":"","ctime":1718314262335,"mtime":1718314262335},"display":"Python 3.1.x ('base')","version":{"major":3,"minor":1,"micro":-1},"arch":1,"distro":{"org":"Anaconda, Inc."},"source":[],"type":"Conda","id":"/opt/conda/bin/python","detailedDisplayName":"Python 3.1.x ('base': conda)"} to {"arch":1,"executable":{"filename":"/opt/conda/bin/python","ctime":-1,"mtime":-1,"sysPrefix":"/opt/conda"},"version":{"major":3,"minor":1,"micro":-1}} 2024-06-20 07:45:14.298 [debug] Resolved /opt/conda/bin/python using downstream locator 2024-06-20 07:45:14.298 [debug] Flushing env to cache /opt/conda/bin/python 2024-06-20 07:45:14.298 [error] Invalid version for /opt/conda/bin/python: {"name":"base","location":"/opt/conda","kind":"virt-conda","executable":{"filename":"/opt/conda/bin/python","sysPrefix":"/opt/conda","ctime":1718314262335,"mtime":1718314262335},"display":"Python 3.1.x ('base')","version":{"major":3,"minor":1,"micro":-1},"arch":1,"distro":{"org":"Anaconda, Inc."},"source":[],"type":"Conda","id":"/opt/conda/bin/python","detailedDisplayName":"Python 3.1.x ('base': conda)"} 2024-06-20 07:45:14.304 [debug] Found cached env for /opt/conda/bin/python 2024-06-20 07:45:14.322 [debug] Activating Environment to capture Environment variables, conda run -n base --no-capture-output python /home/mambauser/.vscode-server/extensions/ms-python.python-2024.8.1/python_files/get_output_via_markers.py /home/mambauser/.vscode-server/extensions/ms-python.python-2024.8.1/python_files/printEnvVariables.py 2024-06-20 07:45:14.322 [info] > conda run -n base --no-capture-output python ~/.vscode-server/extensions/ms-python.python-2024.8.1/python_files/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2024.8.1/python_files/printEnvVariables.py 2024-06-20 07:45:14.322 [info] shell: bash ... ```

Steps to reproduce:

  1. Start VS Code and initialize the Python extension. (Unfortunately this is not 100% reproducible for me, and I haven't been able to isolate precisely which conditions cause it.)

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` XXX ```

Extension version: 2024.8.1 VS Code version: Code 1.90.1 (611f9bfce64f25108829dd295f54a6894e87339d, 2024-06-11T21:02:43.666Z) OS version: Linux x64 5.15.0-107-generic Modes: Remote OS version: Linux x64 5.15.0-107-generic

User Settings

``` condaPath: "" languageServer: "Pylance" testing • pytestArgs: "" • pytestEnabled: true terminal • activateEnvironment: false experiments • enabled: false ```

Installed Extensions |Extension Name|Extension Id|Version| |---|---|---| |Docker|ms-azuretools.vscode-docker|1.29.1| |Git History|donjayamanne.githistory|0.6.20| |GitHub Copilot|GitHub.copilot|1.204.0| |GitHub Copilot Chat|GitHub.copilot-chat|0.16.1| |GitLens — Git supercharged|eamodio.gitlens|15.1.0| |hadolint|exiasr.hadolint|1.1.2| |JavaScript Debugger|ms-vscode.js-debug|1.90.0| |Jupyter|ms-toolsai.jupyter|2024.5.0| |Jupyter Cell Tags|ms-toolsai.vscode-jupyter-cell-tags|0.1.9| |Jupyter Notebook Renderers|ms-toolsai.jupyter-renderers|1.0.18| |Jupyter Slide Show|ms-toolsai.vscode-jupyter-slideshow|0.1.6| |Live Share|ms-vsliveshare.vsliveshare|1.0.5932| |markdownlint|DavidAnson.vscode-markdownlint|0.55.0| |Pylance|ms-python.vscode-pylance|2024.6.1| |Python|ms-python.python|2024.8.1| |Python Debugger|ms-python.debugpy|2024.6.0| |Resource Monitor|mutantdino.resourcemonitor|1.0.7| |Ruff|charliermarsh.ruff|2024.28.0| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.9| |Xonsh IDE|jnoortheen.xonsh|0.3.3|
System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz (8 x 3708)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
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| |Load (avg)|7, 6, 7| |Memory (System)|62.75GB (15.50GB free)| |Process Argv|--log ms-python.python=debug| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|ubuntu| |XDG_CURRENT_DESKTOP|Unity| |XDG_SESSION_DESKTOP|ubuntu| |XDG_SESSION_TYPE|x11| |Item|Value| |---|---| |Remote|Dev Container: projectname| |OS|Linux x64 5.15.0-107-generic| |CPUs|Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz (8 x 3708)| |Memory (System)|62.75GB (15.50GB free)| |VM|0%|
kilianjn commented 4 months ago

Exactly the same problem. I have as well problems with the debugger which requires at least version 3.7 . Have problems calling figures from matplotlib from the debugger.

I switched to the pre release version of Python Debugger and the Python version seems to be the correct again. Problems with the debugger persist though

thiagojramos commented 4 months ago

Same issue here. The conda base environment shows as Python 3.1. Both conda and VS 2022 are up to date. Conda.exe and the scripts folder are set in the options. The Python version in the conda base is 3.12.

Details

![2024-06-23 (14)](https://github.com/microsoft/vscode-python/assets/45890502/2e2db64f-cd35-4625-94a9-4ac34f4ef378) ![2024-06-23 (15)](https://github.com/microsoft/vscode-python/assets/45890502/8f4ee37f-1da6-4ed5-848a-4e245d7fc0af) ![2024-06-23 (16)](https://github.com/microsoft/vscode-python/assets/45890502/9feecd3e-e020-4be4-95f0-71385a721329)

Himanshunitrr commented 4 months ago

Having the same issue, any updates on this?

karthiknadig commented 4 months ago

Please try the pre-release version of the python extension. It has a potential fix for this.

Himanshunitrr commented 4 months ago

Thanks, it works

CHLEE-Leo commented 4 months ago

Please try the pre-release version of the python extension. It has a potential fix for this.

I had the same issue and fixed it following your advice. What was the cause of error? @karthiknadig

lalvarezpoli commented 4 months ago

Please try the pre-release version of the python extension. It has a potential fix for this.

Sorry for the dumb question, but what does this mean exactly? Is it within the VsCode settings, or update the virtual env?

maresb commented 4 months ago

@lalvarezpoli: image

See the "Switch to pre-release version" button

rubensa commented 3 months ago

I think this is caused because conda creates a symlink called python3.1 pointing to python3.10, python3.11 or python3.12 (whichever version you installed) for Python >=3.10. See: https://github.com/conda/conda/issues/11423#issuecomment-1104253815