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

Can't find envs, please help me #1

Closed
WXZhao7 opened this issue Jun 1, 2024 · 7 comments
Closed

Can't find envs, please help me #1

WXZhao7 opened this issue Jun 1, 2024 · 7 comments

Comments

@WXZhao7
Copy link

WXZhao7 commented Jun 1, 2024

Thanks for you scripts! I found your comment and try to use it. microsoft/vscode-python#20919 (comment)
I'm sure the hacked conda.sh changed the json but vscode-python still can't find the venv created by micromamba. Any suggestions?

  • test the script
> ~/Program/micromamba/conda.sh info --json
{ "root_prefix": "/home/wxz/Program/micromamba", "channels": [ "https://conda.anaconda.org/conda-forge/linux-64", "https://conda.anaconda.org/conda-forge/noarch" ], "curl version": "libcurl/8.6.0 OpenSSL/3.2.1 zlib/1.2.13 zstd/1.5.5 libssh2/1.11.0 nghttp2/1.58.0", "env location": "-", "environment": "None (not found)", "envs_dirs": [ "/home/wxz/Program/micromamba/envs" ], "libarchive version": "libarchive 3.7.2 zlib/1.2.13 bz2lib/1.0.8 libzstd/1.5.5", "libmamba version": "1.5.8", "micromamba version": "1.5.8", "pkgs_dirs": [ "/home/wxz/Program/micromamba/pkgs", "/home/wxz/.mamba/pkgs" ], "platform": "linux-64", "populated config files": [ "/home/wxz/.condarc" ], "user config files": [ "/home/wxz/.mambarc" ], "virtual packages": [ "__unix=0=0", "__linux=6.8.4=0", "__glibc=2.39=0", "__archspec=1=x86_64-v3" ], "envs": [ "/home/wxz/Program/micromamba", "/home/wxz/Program/micromamba/envs/pre", "/home/wxz/Program/micromamba/envs/rec", "/home/wxz/Program/micromamba/envs/seism", "/home/wxz/Program/micromamba/envs/seismic" ] }
  • output of vscode-python

It seems that vscode-python need /path/to/env/bin/conda info --json.

2024-06-01 12:47:30.619 [info] Experiment 'pythonCreateEnvOnPipInstall' is active
2024-06-01 12:47:30.619 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-06-01 12:47:30.619 [info] Experiment 'pythonSurveyNotification' is active
2024-06-01 12:47:30.619 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-06-01 12:47:30.619 [info] Experiment 'pythonTestAdapter' is active
2024-06-01 12:47:30.619 [info] Default formatter is set to ms-python.black-formatter for workspace /home/wxz/Program/python/toolkit
2024-06-01 12:47:30.619 [info] > ~/Program/micromamba/conda.sh info --json
2024-06-01 12:47:30.619 [info] > hatch env show --json
2024-06-01 12:47:30.619 [info] cwd: .
2024-06-01 12:47:30.634 [info] > conda info --json
2024-06-01 12:47:30.638 [info] Found: /bin/python --> /bin/python3.12
2024-06-01 12:47:30.642 [info] > ~/.conda/bin/conda info --json
2024-06-01 12:47:30.645 [info] > ~/.condarc/bin/conda info --json
2024-06-01 12:47:30.647 [info] Found: /bin/python3 --> /bin/python3.12
2024-06-01 12:47:30.647 [info] Found: /bin/python3.12 --> /bin/python3.12
2024-06-01 12:47:30.650 [info] > ~/Program/micromamba/envs/pre/bin/conda info --json
2024-06-01 12:47:30.653 [info] > ~/Program/micromamba/envs/rec/bin/conda info --json
2024-06-01 12:47:30.657 [info] > ~/Program/micromamba/envs/seism/bin/conda info --json
2024-06-01 12:47:30.664 [info] > ~/Program/micromamba/envs/seismic/bin/conda info --json
2024-06-01 12:47:30.676 [info] Found: /sbin/python --> /sbin/python3.12
2024-06-01 12:47:30.677 [info] Found: /sbin/python3 --> /sbin/python3.12
2024-06-01 12:47:30.677 [info] Found: /sbin/python3.12 --> /sbin/python3.12
2024-06-01 12:47:30.681 [info] Found: /usr/bin/python --> /usr/bin/python3.12
2024-06-01 12:47:30.681 [info] Found: /usr/bin/python3 --> /usr/bin/python3.12
2024-06-01 12:47:30.681 [info] Found: /usr/bin/python3.12 --> /usr/bin/python3.12
2024-06-01 12:47:30.929 [info] > pyenv which python
2024-06-01 12:47:30.929 [info] cwd: .
2024-06-01 12:47:30.946 [info] > python -c "import sys;print(sys.executable)"
2024-06-01 12:47:30.955 [info] Found: /usr/sbin/python --> /usr/sbin/python3.12
2024-06-01 12:47:30.955 [info] Found: /usr/sbin/python3 --> /usr/sbin/python3.12
2024-06-01 12:47:30.955 [info] Found: /usr/sbin/python3.12 --> /usr/sbin/python3.12
2024-06-01 12:47:30.970 [info] > /bin/python -I ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py
2024-06-01 12:47:31.002 [info] > /usr/bin/python -I ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py
2024-06-01 12:47:31.006 [info] > /sbin/python -I ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py
2024-06-01 12:47:31.032 [info] > /usr/sbin/python -I ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py
2024-06-01 12:47:31.072 [info] > pyenv which python
2024-06-01 12:47:31.072 [info] cwd: .
2024-06-01 12:47:31.099 [info] Python interpreter path: /usr/bin/python
2024-06-01 12:47:32.425 [warning] Shell integration may not be active, environment activated may be overridden by the shell.
2024-06-01 12:47:33.130 [info] Starting Pylance language server.
@suimong
Copy link
Owner

suimong commented Jun 1, 2024

Could you turn on the trace level logging for vscode-python extension and paste the log here?

By the look of it, ~/Program/micromamba/conda.sh info --json is called only once, but vscode-python tries to look for conda in other places (envs/<env>/conda etc.) in subsequent calls to info --json which should not happen.

Btw the script is tested on Linux only, so I may not be of much help if you are using MacOS.

@WXZhao7
Copy link
Author

WXZhao7 commented Jun 1, 2024

Thanks! I run VScode in Arch Linux. And I reproduce this problem below.

  1. create a new profile and install vscode-python extension.
  2. add "python.condaPath": "/home/wxz/Program/micromamba/conda.sh" in the settings.
  3. switch log level to trace
  4. Python: Clear cache and Reload window.
2024-06-01 19:24:15.226 [info] Experiment 'pythonCreateEnvOnPipInstall' is active
2024-06-01 19:24:15.226 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-06-01 19:24:15.226 [info] Experiment 'pythonSurveyNotification' is active
2024-06-01 19:24:15.226 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-06-01 19:24:15.226 [info] Experiment 'pythonTestAdapter' is active
2024-06-01 19:24:15.231 [info] > python -c "import sys;print(sys.executable)"
2024-06-01 19:24:15.242 [info] Python interpreter path: /usr/bin/python
2024-06-01 19:24:16.235 [warning] Shell integration may not be active, environment activated may be overridden by the shell.
2024-06-01 19:24:16.350 [info] Starting Pylance language server.
2024-06-01 19:24:21.223 [debug] Terminal shell path '/usr/bin/zsh' identified as shell 'zsh'
2024-06-01 19:24:21.223 [debug] Shell identified as zsh 
2024-06-01 19:24:21.225 [debug] Found cached env for /usr/bin/python
2024-06-01 19:24:31.978 [info] Experiment 'pythonCreateEnvOnPipInstall' is active
2024-06-01 19:24:31.978 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-06-01 19:24:31.979 [info] Experiment 'pythonSurveyNotification' is active
2024-06-01 19:24:31.979 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-06-01 19:24:31.979 [info] Experiment 'pythonTestAdapter' is active
2024-06-01 19:24:31.981 [debug] Start watching file for changes /home/wxz/.conda/environments.txt
2024-06-01 19:24:31.981 [debug] Start watching: /home/wxz/.conda with pattern environments.txt using VSCode API
2024-06-01 19:24:32.002 [debug] Searching for interpreters in posix paths locator
2024-06-01 19:24:32.004 [debug] Searching for pyenv environments
2024-06-01 19:24:32.004 [debug] Searching for conda.
2024-06-01 19:24:32.005 [debug] Probing conda binary: /home/wxz/Program/micromamba/conda.sh
2024-06-01 19:24:32.035 [debug] VS Code was not launched from the command line
2024-06-01 19:24:32.035 [debug] VS Code was not launched from the command line
2024-06-01 19:24:32.036 [debug] Finished searching for custom virtual envs
2024-06-01 19:24:32.036 [debug] Couldn't locate the state binary.
2024-06-01 19:24:32.036 [debug] Dump environment variables {
    "CHROME_DESKTOP": "code-url-handler.desktop",
    "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus",
    "DEBUGINFOD_URLS": "https://debuginfod.archlinux.org ",
    "DESKTOP_SESSION": "xfce",
    "DISPLAY": ":1.0",
    "ELECTRON_NO_ATTACH_CONSOLE": "1",
    "GDK_BACKEND": "x11",
    "GDMSESSION": "xfce",
    "GTK_MODULES": "canberra-gtk-module:canberra-gtk-module",
    "HOME": "/home/wxz",
    "INVOCATION_ID": "204058189e334e299f309f70327bae49",
    "JOURNAL_STREAM": "8:82983580",
    "LANG": "en_US.UTF-8",
    "LOGNAME": "wxz",
    "MEMORY_PRESSURE_WATCH": "/sys/fs/cgroup/system.slice/system-vncserver.slice/vncserver@:1.service/memory.pressure",
    "MEMORY_PRESSURE_WRITE": "c29tZSAyMDAwMDAgMjAwMDAwMAA=",
    "NO_AT_BRIDGE": "1",
    "ORIGINAL_XDG_CURRENT_DESKTOP": "XFCE",
    "PIDFILE": "/run/vncsession-:1.pid",
    "PWD": "/home/wxz",
    "SESSION_MANAGER": "local/arch:@/tmp/.ICE-unix/157,unix/arch:/tmp/.ICE-unix/157",
    "SHELL": "/bin/zsh",
    "SHLVL": "1",
    "SYSTEMD_EXEC_PID": "116",
    "USER": "wxz",
    "USERNAME": "wxz",
    "VSCODE_AMD_ENTRYPOINT": "vs/workbench/api/node/extensionHostProcess",
    "VSCODE_CLI": "1",
    "VSCODE_CODE_CACHE_PATH": "/home/wxz/.config/Code/CachedData/dc96b837cf6bb4af9cd736aa3af08cf8279f7685",
    "VSCODE_CRASH_REPORTER_PROCESS_TYPE": "extensionHost",
    "VSCODE_CWD": "/home/wxz",
    "VSCODE_HANDLES_UNCAUGHT_ERRORS": "true",
    "VSCODE_IPC_HOOK": "/run/user/1000/vscode-12bc7884-1.89-main.sock",
    "VSCODE_NLS_CONFIG": "{\"locale\":\"en\",\"osLocale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}",
    "VSCODE_PID": "8694",
    "XAUTHORITY": "/home/wxz/.Xauthority",
    "XDG_CONFIG_DIRS": "/etc/xdg",
    "XDG_CURRENT_DESKTOP": "XFCE",
    "XDG_DATA_DIRS": "/usr/local/share:/usr/share",
    "XDG_MENU_PREFIX": "xfce-",
    "XDG_RUNTIME_DIR": "/run/user/1000",
    "XDG_SESSION_CLASS": "user",
    "XDG_SESSION_DESKTOP": "xfce",
    "XDG_SESSION_ID": "7375",
    "XDG_SESSION_TYPE": "x11",
    "_": "/opt/visual-studio-code/bin/../code",
    "ELECTRON_RUN_AS_NODE": "1",
    "PATH": "/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl"
}
2024-06-01 19:24:32.039 [info] > ~/Program/micromamba/conda.sh info --json
2024-06-01 19:24:32.042 [debug] Finished searching for global virtual envs
2024-06-01 19:24:32.045 [debug] Attempting to resolve symbolic link: /bin/python
2024-06-01 19:24:32.048 [debug] /home/wxz/Program/micromamba/conda.sh info --json: 

2024-06-01 19:24:32.052 [debug] Failed to spawn conda binary /home/wxz/Program/micromamba/conda.sh [SyntaxError: Unexpected end of JSON input
	at JSON.parse (<anonymous>)
	at _.getInfoImpl (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:573426)
	at async _.locate (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:572536)
	at async a.doIterEnvs (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:539213)
	at async a.iterEnvs (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:518884)
	at async i (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:271493)]
2024-06-01 19:24:32.052 [debug] Probing conda binary: conda
2024-06-01 19:24:32.055 [info] > conda info --json
2024-06-01 19:24:32.056 [debug] Failed to spawn conda binary conda [Error: spawn conda ENOENT
	at ChildProcess._handle.onexit (node:internal/child_process:284:19)
	at onErrorNT (node:internal/child_process:477:16)
	at process.processTicksAndRejections (node:internal/process/task_queues:82:21)] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn conda',
  path: 'conda',
  spawnargs: [ 'info', '--json' ]
}
2024-06-01 19:24:32.058 [info] Found: /bin/python --> /bin/python3.12
2024-06-01 19:24:32.058 [debug] Attempting to resolve symbolic link: /bin/python3
2024-06-01 19:24:32.059 [debug] Probing conda binary: /home/wxz/.conda/bin/conda
2024-06-01 19:24:32.061 [info] > ~/.conda/bin/conda info --json
2024-06-01 19:24:32.062 [debug] Failed to spawn conda binary /home/wxz/.conda/bin/conda [Error: spawn /home/wxz/.conda/bin/conda ENOENT
	at ChildProcess._handle.onexit (node:internal/child_process:284:19)
	at onErrorNT (node:internal/child_process:477:16)
	at process.processTicksAndRejections (node:internal/process/task_queues:82:21)] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /home/wxz/.conda/bin/conda',
  path: '/home/wxz/.conda/bin/conda',
  spawnargs: [ 'info', '--json' ]
}
2024-06-01 19:24:32.062 [debug] Probing conda binary: /home/wxz/.condarc/bin/conda
2024-06-01 19:24:32.065 [info] > ~/.condarc/bin/conda info --json
2024-06-01 19:24:32.066 [debug] Failed to spawn conda binary /home/wxz/.condarc/bin/conda [Error: spawn ENOTDIR
	at ChildProcess.spawn (node:internal/child_process:414:11)
	at spawn (node:child_process:799:9)
	at t.plainExec (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:221240)
	at a.exec (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:208367)
	at t.exec (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:593139)
	at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
	at async _.getInfoImpl (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:573274)
	at async _.locate (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:572536)
	at async a.doIterEnvs (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:539213)
	at async a.iterEnvs (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:518884)
	at async i (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:271493)] {
  errno: -20,
  code: 'ENOTDIR',
  syscall: 'spawn'
}
2024-06-01 19:24:32.087 [info] Found: /bin/python3 --> /bin/python3.12
2024-06-01 19:24:32.087 [debug] Attempting to resolve symbolic link: /bin/python3.12
2024-06-01 19:24:32.099 [info] Found: /bin/python3.12 --> /bin/python3.12
2024-06-01 19:24:32.104 [debug] Probing conda binary: /home/wxz/Program/micromamba/envs/pre/bin/conda
2024-06-01 19:24:32.106 [info] > ~/Program/micromamba/envs/pre/bin/conda info --json
2024-06-01 19:24:32.106 [debug] Failed to spawn conda binary /home/wxz/Program/micromamba/envs/pre/bin/conda [Error: spawn /home/wxz/Program/micromamba/envs/pre/bin/conda ENOENT
	at ChildProcess._handle.onexit (node:internal/child_process:284:19)
	at onErrorNT (node:internal/child_process:477:16)
	at process.processTicksAndRejections (node:internal/process/task_queues:82:21)] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /home/wxz/Program/micromamba/envs/pre/bin/conda',
  path: '/home/wxz/Program/micromamba/envs/pre/bin/conda',
  spawnargs: [ 'info', '--json' ]
}
2024-06-01 19:24:32.106 [debug] Probing conda binary: /home/wxz/Program/micromamba/envs/rec/bin/conda
2024-06-01 19:24:32.108 [info] > ~/Program/micromamba/envs/rec/bin/conda info --json
2024-06-01 19:24:32.109 [debug] Failed to spawn conda binary /home/wxz/Program/micromamba/envs/rec/bin/conda [Error: spawn /home/wxz/Program/micromamba/envs/rec/bin/conda ENOENT
	at ChildProcess._handle.onexit (node:internal/child_process:284:19)
	at onErrorNT (node:internal/child_process:477:16)
	at process.processTicksAndRejections (node:internal/process/task_queues:82:21)] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /home/wxz/Program/micromamba/envs/rec/bin/conda',
  path: '/home/wxz/Program/micromamba/envs/rec/bin/conda',
  spawnargs: [ 'info', '--json' ]
}
2024-06-01 19:24:32.109 [debug] Probing conda binary: /home/wxz/Program/micromamba/envs/seism/bin/conda
2024-06-01 19:24:32.111 [info] > ~/Program/micromamba/envs/seism/bin/conda info --json
2024-06-01 19:24:32.111 [debug] Failed to spawn conda binary /home/wxz/Program/micromamba/envs/seism/bin/conda [Error: spawn /home/wxz/Program/micromamba/envs/seism/bin/conda ENOENT
	at ChildProcess._handle.onexit (node:internal/child_process:284:19)
	at onErrorNT (node:internal/child_process:477:16)
	at process.processTicksAndRejections (node:internal/process/task_queues:82:21)] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /home/wxz/Program/micromamba/envs/seism/bin/conda',
  path: '/home/wxz/Program/micromamba/envs/seism/bin/conda',
  spawnargs: [ 'info', '--json' ]
}
2024-06-01 19:24:32.111 [debug] Probing conda binary: /home/wxz/Program/micromamba/envs/seismic/bin/conda
2024-06-01 19:24:32.114 [info] > ~/Program/micromamba/envs/seismic/bin/conda info --json
2024-06-01 19:24:32.114 [debug] Failed to spawn conda binary /home/wxz/Program/micromamba/envs/seismic/bin/conda [Error: spawn /home/wxz/Program/micromamba/envs/seismic/bin/conda ENOENT
	at ChildProcess._handle.onexit (node:internal/child_process:284:19)
	at onErrorNT (node:internal/child_process:477:16)
	at process.processTicksAndRejections (node:internal/process/task_queues:82:21)] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /home/wxz/Program/micromamba/envs/seismic/bin/conda',
  path: '/home/wxz/Program/micromamba/envs/seismic/bin/conda',
  spawnargs: [ 'info', '--json' ]
}
2024-06-01 19:24:32.114 [debug] Couldn't locate the conda binary.
2024-06-01 19:24:32.114 [debug] Couldn't locate the conda binary.
2024-06-01 19:24:32.145 [debug] Attempting to resolve symbolic link: /sbin/python
2024-06-01 19:24:32.146 [info] Found: /sbin/python --> /sbin/python3.12
2024-06-01 19:24:32.146 [debug] Attempting to resolve symbolic link: /sbin/python3
2024-06-01 19:24:32.147 [info] Found: /sbin/python3 --> /sbin/python3.12
2024-06-01 19:24:32.147 [debug] Attempting to resolve symbolic link: /sbin/python3.12
2024-06-01 19:24:32.147 [info] Found: /sbin/python3.12 --> /sbin/python3.12
2024-06-01 19:24:32.150 [debug] Attempting to resolve symbolic link: /usr/bin/python
2024-06-01 19:24:32.153 [info] Found: /usr/bin/python --> /usr/bin/python3.12
2024-06-01 19:24:32.153 [debug] Attempting to resolve symbolic link: /usr/bin/python3
2024-06-01 19:24:32.153 [info] Found: /usr/bin/python3 --> /usr/bin/python3.12
2024-06-01 19:24:32.153 [debug] Attempting to resolve symbolic link: /usr/bin/python3.12
2024-06-01 19:24:32.153 [info] Found: /usr/bin/python3.12 --> /usr/bin/python3.12
2024-06-01 19:24:32.172 [debug] Attempting to resolve symbolic link: /usr/sbin/python
2024-06-01 19:24:32.173 [info] Found: /usr/sbin/python --> /usr/sbin/python3.12
2024-06-01 19:24:32.173 [debug] Attempting to resolve symbolic link: /usr/sbin/python3
2024-06-01 19:24:32.174 [info] Found: /usr/sbin/python3 --> /usr/sbin/python3.12
2024-06-01 19:24:32.174 [debug] Attempting to resolve symbolic link: /usr/sbin/python3.12
2024-06-01 19:24:32.174 [info] Found: /usr/sbin/python3.12 --> /usr/sbin/python3.12
2024-06-01 19:24:32.174 [debug] Found 4 python binaries in posix paths
2024-06-01 19:24:32.182 [debug] Best effort version B for /bin/python {"major":3,"minor":12,"micro":-1}
2024-06-01 19:24:32.184 [debug] Best effort version C for /bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}}
2024-06-01 19:24:32.185 [debug] Best effort version D for /bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}}
2024-06-01 19:24:32.187 [debug] Python API env change detected /bin/python add
2024-06-01 19:24:32.190 [info] > /bin/python -I ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py
2024-06-01 19:24:32.196 [debug] Best effort version B for /sbin/python {"major":3,"minor":12,"micro":-1}
2024-06-01 19:24:32.196 [debug] Best effort version C for /sbin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}}
2024-06-01 19:24:32.196 [debug] Best effort version D for /sbin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}}
2024-06-01 19:24:32.197 [debug] Python API env change detected /sbin/python add
2024-06-01 19:24:32.200 [info] > /sbin/python -I ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py
2024-06-01 19:24:32.207 [debug] Best effort version B for /usr/bin/python {"major":3,"minor":12,"micro":-1}
2024-06-01 19:24:32.208 [debug] Best effort version C for /usr/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}}
2024-06-01 19:24:32.208 [debug] Best effort version D for /usr/bin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}}
2024-06-01 19:24:32.208 [debug] Python API env change detected /usr/bin/python add
2024-06-01 19:24:32.208 [debug] Finished searching for interpreters in posix paths locator
2024-06-01 19:24:32.214 [debug] Best effort version B for /usr/sbin/python {"major":3,"minor":12,"micro":-1}
2024-06-01 19:24:32.216 [debug] Best effort version C for /usr/sbin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}}
2024-06-01 19:24:32.216 [debug] Best effort version D for /usr/sbin/python {"major":-1,"minor":-1,"micro":-1,"release":{"level":"final","serial":-1}}
2024-06-01 19:24:32.217 [debug] Python API env change detected /usr/sbin/python add
2024-06-01 19:24:32.217 [debug] Finished with environment reducer
2024-06-01 19:24:32.220 [debug] Found interpreter for >> /bin/python -I /home/wxz/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py /home/wxz/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py <<: {"versionInfo":[3,12,3,"final",0],"sysPrefix":"/usr","sysVersion":"3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]","is64Bit":true}
2024-06-01 19:24:32.223 [info] > /usr/bin/python -I ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py
2024-06-01 19:24:32.223 [debug] Python API env change detected /bin/python update
2024-06-01 19:24:32.235 [debug] Found interpreter for >> /sbin/python -I /home/wxz/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py /home/wxz/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py <<: {"versionInfo":[3,12,3,"final",0],"sysPrefix":"/usr","sysVersion":"3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]","is64Bit":true}
2024-06-01 19:24:32.238 [info] > /usr/sbin/python -I ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py
2024-06-01 19:24:32.238 [debug] Python API env change detected /sbin/python update
2024-06-01 19:24:32.248 [debug] Found interpreter for >> /usr/bin/python -I /home/wxz/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py /home/wxz/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py <<: {"versionInfo":[3,12,3,"final",0],"sysPrefix":"/usr","sysVersion":"3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]","is64Bit":true}
2024-06-01 19:24:32.249 [debug] Python API env change detected /usr/bin/python update
2024-06-01 19:24:32.266 [debug] Found interpreter for >> /usr/sbin/python -I /home/wxz/.vscode/extensions/ms-python.python-2024.6.0/python_files/get_output_via_markers.py /home/wxz/.vscode/extensions/ms-python.python-2024.6.0/python_files/interpreterInfo.py <<: {"versionInfo":[3,12,3,"final",0],"sysPrefix":"/usr","sysVersion":"3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]","is64Bit":true}
2024-06-01 19:24:32.266 [debug] Python API env change detected /usr/sbin/python update
2024-06-01 19:24:32.266 [debug] Finished with environment resolver
2024-06-01 19:24:32.268 [debug] Environments added to cache [{"name":"","location":"/","kind":"virt-virtualenv","executable":{"filename":"/bin/python","sysPrefix":"/usr","ctime":1714270021619,"mtime":1713863767000},"display":"Python 3.12.3","version":{"major":3,"minor":12,"micro":3,"release":{"level":"final","serial":0},"sysVersion":"3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]"},"arch":3,"distro":{"org":""},"source":["path env var"],"type":"Virtual","id":"/bin/python","detailedDisplayName":"Python 3.12.3 (virtualenv)"},{"name":"sbin","location":"/sbin","kind":"virt-virtualenv","executable":{"filename":"/sbin/python","sysPrefix":"/usr","ctime":1714270021619,"mtime":1713863767000},"display":"Python 3.12.3 ('sbin')","version":{"major":3,"minor":12,"micro":3,"release":{"level":"final","serial":0},"sysVersion":"3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]"},"arch":3,"distro":{"org":""},"source":["path env var"],"type":"Virtual","id":"/sbin/python","detailedDisplayName":"Python 3.12.3 ('sbin': virtualenv)"},{"name":"usr","location":"/usr","kind":"virt-virtualenv","executable":{"filename":"/usr/bin/python","sysPrefix":"/usr","ctime":1714270021619,"mtime":1713863767000},"display":"Python 3.12.3 ('usr')","version":{"major":3,"minor":12,"micro":3,"release":{"level":"final","serial":0},"sysVersion":"3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]"},"arch":3,"distro":{"org":""},"source":["path env var"],"type":"Virtual","id":"/usr/bin/python","detailedDisplayName":"Python 3.12.3 ('usr': virtualenv)"},{"name":"sbin","location":"/usr/sbin","kind":"virt-virtualenv","executable":{"filename":"/usr/sbin/python","sysPrefix":"/usr","ctime":1714270021619,"mtime":1713863767000},"display":"Python 3.12.3 ('sbin')","version":{"major":3,"minor":12,"micro":3,"release":{"level":"final","serial":0},"sysVersion":"3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]"},"arch":3,"distro":{"org":""},"source":["path env var"],"type":"Virtual","id":"/usr/sbin/python","detailedDisplayName":"Python 3.12.3 ('sbin': virtualenv)"}]
2024-06-01 19:24:32.273 [info] > python -c "import sys;print(sys.executable)"
2024-06-01 19:24:32.283 [debug] Needed to validate /usr/bin/python with latest info
2024-06-01 19:24:32.283 [info] Python interpreter path: /usr/bin/python
2024-06-01 19:24:32.284 [debug] Needed to validate /usr/bin/python with latest info
2024-06-01 19:24:32.284 [debug] Needed to validate /usr/bin/python with latest info
2024-06-01 19:24:32.286 [debug] Found cached env for /usr/bin/python
2024-06-01 19:24:32.422 [debug] Extension ms-python.vscode-pylance accessed onDidChangeActiveEnvironmentPath with args: undefined
2024-06-01 19:24:32.422 [debug] Extension ms-python.vscode-pylance accessed onDidEnvironmentVariablesChange with args: undefined
2024-06-01 19:24:33.275 [debug] Did we determine shell integration to be working for zsh ? false
2024-06-01 19:24:33.276 [warning] Shell integration may not be active, environment activated may be overridden by the shell.
2024-06-01 19:24:33.277 [debug] Found cached env for /usr/bin/python
2024-06-01 19:24:33.281 [debug] Activation Commands received undefined for shell /usr/bin/zsh, resource undefined and interpreter /usr/bin/python
2024-06-01 19:24:33.281 [debug] Activated environment variables for undefined undefined
2024-06-01 19:24:33.282 [debug] Found cached env for /usr/bin/python
2024-06-01 19:24:33.284 [debug] Activation Commands received undefined for shell bash, resource undefined and interpreter /usr/bin/python
2024-06-01 19:24:33.285 [debug] Activated environment variables for undefined undefined
2024-06-01 19:24:33.303 [info] Starting Pylance language server.
2024-06-01 19:24:33.306 [debug] Found cached env for /usr/bin/python
2024-06-01 19:24:38.001 [debug] Terminal shell path '/usr/bin/zsh' identified as shell 'zsh'
2024-06-01 19:24:38.001 [debug] Shell identified as zsh 
2024-06-01 19:24:38.002 [debug] Found cached env for /usr/bin/python

@suimong
Copy link
Owner

suimong commented Jun 1, 2024

So this might be the log entry that points to the problem:

2024-06-01 19:24:32.052 [debug] Failed to spawn conda binary /home/wxz/Program/micromamba/conda.sh [SyntaxError: Unexpected end of JSON input
	at JSON.parse (<anonymous>)
	at _.getInfoImpl (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:573426)
	at async _.locate (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:572536)
	at async a.doIterEnvs (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:539213)
	at async a.iterEnvs (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:518884)
	at async i (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:271493)]

I was tripped by this line as well, and in my case it turned out that vscode-python was executing the script with sh rather than bash. Maybe you could try to adjust the shebang line to correctly point to bash on your system.

@WXZhao7
Copy link
Author

WXZhao7 commented Jun 1, 2024

Thanks again.
I guess the conda.sh is correct.

> head /home/wxz/Program/micromamba/conda.sh
#!/bin/bash
# Adapted from micromamba/etc/profile.d/micromamba.sh
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause

__mamba_exe() (
    "$MAMBA_EXE" "${@}"

I have tried many times, but nothing has changed.

I also can't understand why the vscode-python said SyntaxError: Unexpected end of JSON input

024-06-01 20:35:29.962 [info] > ~/Program/micromamba/conda.sh info --json
2024-06-01 20:35:29.966 [debug] Finished searching for global virtual envs
2024-06-01 20:35:29.970 [debug] Attempting to resolve symbolic link: /bin/python
2024-06-01 20:35:29.972 [debug] /home/wxz/Program/micromamba/conda.sh info --json: 

2024-06-01 20:35:29.977 [debug] Failed to spawn conda binary /home/wxz/Program/micromamba/conda.sh [SyntaxError: Unexpected end of JSON input
	at JSON.parse (<anonymous>)
	at _.getInfoImpl (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:573426)
	at async _.locate (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:572536)
	at async a.doIterEnvs (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:539213)
	at async a.iterEnvs (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:518884)
	at async i (/home/wxz/.vscode/extensions/ms-python.python-2024.6.0/out/client/extension.js:2:271493)]
2024-06-01 20:35:29.977 [debug] Probing conda binary: conda

Finally, I found somthing by a simple test.

  • I modify the conda.sh to output the _info and _envs.
            # replace some keys to conda info --json spec
            # .. so that VSCode can recognize them
            local _info=$(__mamba_exe "${@}" \
            | sed 's/envs directories/envs_dirs/' \
            | sed 's/package cache/pkgs_dirs/' \
            | sed 's/base environment/root_prefix/' \
            || \exit)
            echo "info" >> /home/wxz/log.txt
            echo $_info >> /home/wxz/log.txt
            local _envs=$(__mamba_exe env list --json)
            echo "env" >> /home/wxz/log.txt
            local _combined=$(jq -s '.[0] * .[1]' <(echo $_info) <(echo $_envs))
  • Python: Clear cache and Reload window. The script broken due to unknow error.
> cat log.txt
info

env
  • run the conda.sh in the terminal
> cat log.txt

info

env

info
{ "root_prefix": "/home/wxz/Program/micromamba", "channels": null, "curl version": "libcurl/8.6.0 OpenSSL/3.2.1 zlib/1.2.13 zstd/1.5.5 libssh2/1.11.0 nghttp2/1.58.0", "env location": "/home/wxz/Program/micromamba/envs/seismic", "environment": "seismic (active)", "envs_dirs": [ "/home/wxz/Program/micromamba/envs" ], "libarchive version": "libarchive 3.7.2 zlib/1.2.13 bz2lib/1.0.8 libzstd/1.5.5", "libmamba version": "1.5.8", "micromamba version": "1.5.8", "pkgs_dirs": [ "/home/wxz/Program/micromamba/pkgs", "/home/wxz/.mamba/pkgs" ], "platform": "linux-64", "populated config files": null, "user config files": [ "/home/wxz/.mambarc" ], "virtual packages": [ "__unix=0=0", "__linux=6.8.4=0", "__glibc=2.39=0", "__archspec=1=x86_64-v3" ] }
env
{ "envs": [ "/home/wxz/Program/micromamba", "/home/wxz/Program/micromamba/envs/pre", "/home/wxz/Program/micromamba/envs/rec", "/home/wxz/Program/micromamba/envs/seism", "/home/wxz/Program/micromamba/envs/seismic" ] }

I will try to debug it. Do you have other ideals?

@WXZhao7
Copy link
Author

WXZhao7 commented Jun 1, 2024

The crack is due to the environment variables.
During the vscode-python run the conda.sh, it can't get MAMBA_EXE and MAMBA_ROOT_PERFIX and jq popped SyntaxError: Unexpected end of JSON input at JSON.parse.
Should I hard code both MAMBA_EXE and MAMBA_ROOT_PERFIX in the conda.sh? I don't understand why vscode-python does not inherit environment variables.

@suimong
Copy link
Owner

suimong commented Jun 1, 2024

Glad that you have identified the root cause! IMHO hard code paths is perfectly fine in this case as the whole thing is a hack anyway.

On the other hand, the fact that vscode-python on my machine successfully finds $MAMBA_EXE and $MAMBA_ROOT_PREFIX may suggest that the environment from which you start VSCode does not have these variables set. Perhaps you could try starting VScode from a shell where you are sure the env vars are set?

@WXZhao7
Copy link
Author

WXZhao7 commented Jun 1, 2024

Python extension does not have access to .zshrc. microsoft/vscode-python#22927 (comment)

Yes, you are right. When the VScode is launched in terminal, it does inherit vars from terminal.
To make sure the conda.sh work forever, just add export MAMBA_EXE=***; export MAMBA_ROOT_PREFIX=***;.
Thanks for your help again.

@WXZhao7 WXZhao7 closed this as completed Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants