VSCode Python Extension in WSL2 - Error: Failed to get interpreter information for '~/.pyenv/shims/python3.6'

VSCode Python Extension in WSL2 - Error: Failed to get interpreter information for '~/.pyenv/shims/python3.6'

我在 WSL2:Ubuntu 20.04 中进行 Python/Django 开发。当用 code . 打开 VSCode 时,Python 扩展会卡住并显示消息“Python 扩展正在加载...”。在输出部分,出现以下代码:

User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'AA_testing - experiment'
User belongs to experiment group 'LocalZMQKernel - experiment'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'RunByLine - experiment'
User belongs to experiment group 'CustomEditorSupport - control'
Error 2021-01-23 12:33:35: Failed to initialize source map support in extension
User belongs to experiment group 'pythonaacf'
User belongs to experiment group 'pythonJoinMailingListVar2'
User belongs to experiment group 'pythonSendEntireLineToREPL'
User belongs to experiment group 'pythonInstallPylintButtonFirst'
> conda --version
> conda info --json
> python3.7 ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
Error 2021-01-23 12:33:37: Detection of Python Interpreter for Command python3.6 and args  failed as file  does not exist
Error 2021-01-23 12:33:39: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file 'vscode-remote://wsl+ubuntu-20.04/home/ben/.config/Code/User/settings.json' (EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, open '/home/ben/.config/Code/User/settings.json')
    at _handleError (/home/ben/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/out/vs/server/remoteExtensionHostProcess.js:769:473)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async y.readText (/home/ben/.vscode-server/extensions/ms-python.python-2021.1.502429796/out/client/extension.js:9:344778)
    at async p.doesFileNeedToBeFixed (/home/ben/.vscode-server/extensions/ms-python.python-2021.1.502429796/out/client/extension.js:59:500280)
    at async /home/ben/.vscode-server/extensions/ms-python.python-2021.1.502429796/out/client/extension.js:59:499407
    at async Promise.all (index 0)
    at async p.getFilesToBeFixed (/home/ben/.vscode-server/extensions/ms-python.python-2021.1.502429796/out/client/extension.js:59:499353)
    at async p.updateTestSettings (/home/ben/.vscode-server/extensions/ms-python.python-2021.1.502429796/out/client/extension.js:59:498980)] {
  code: 'FileNotFound',
  name: 'EntryNotFound (FileSystemError)'
}
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py pylint --load-plugins pylint-flask --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text ~/Code/eons-website/eons_backend/eons_data/models.py
cwd: ~/Code/eons-website
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py pylint --load-plugins pylint-flask --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text ~/Code/eons-website/eons_backend/eons_data/models.py
cwd: ~/Code/eons-website
Python interpreter path: ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python
Starting Jedi Python language engine.
> conda --version
##########Linting Output - pylint##########
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.prefix)"
cwd: ~/Code/eons-website
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.prefix)"
cwd: ~/Code/eons-website
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
cwd: ~/Code/eons-website
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
cwd: ~/Code/eons-website
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/Code/eons-website
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/Code/eons-website
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py site --user-site
cwd: ~/Code/eons-website
> ~/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python ~/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py site --user-site
cwd: ~/Code/eons-website
Error 2021-01-23 12:33:40: Failed to get interpreter information for '/home/ben/.pyenv/shims/python3.6' [Error: Command failed: "/home/ben/.pyenv/shims/python3.6" "/home/ben/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py" "/home/ben/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/interpreterInfo.py"
pyenv: python3.6: command not found

The `python3.6' command exists in these Python versions:
  3.6.12

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:223:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Socket.<anonymous> (internal/child_process.js:430:11)
    at Socket.emit (events.js:223:5)
    at Pipe.<anonymous> (net.js:664:12)] {
  killed: false,
  code: 127,
  signal: null,
  cmd: '"/home/ben/.pyenv/shims/python3.6" "/home/ben/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py" "/home/ben/.vscode-server/extensions/ms-python.python-2021.1.502429796/pythonFiles/interpreterInfo.py"'
}

我试过卸载扩展并重新安装 - 有时这似乎有效,但大多数情况下无效。我还手动删除了'~/.vscode-server/extensions`中的所有扩展文件,这也不起作用。

pyenv 中查找 python3.6 命令似乎挂断了,但我不需要它来查找此可执行文件。我工作的环境在 ~/.local/share/virtualenvs/<env-name>/bin 中有自己的 python 可执行文件,当前版本为 3.8.5.

这是在本地 .vscode/settings.json 文件中定义的:

{
    "python.pythonPath": "/home/ben/.local/share/virtualenvs/eons_backend-AMh9NQBG/bin/python",
}

我应该如何配置扩展程序以忽略 Python 的 pyenv 安装?

我通过将 Python 扩展的版本降级到 v2021.1.502429796 解决了这个问题。希望这在某个时候得到解决。