VSCode 在 select 解释器选项中不显示诗歌 virtualenvs

VSCode doesn't show poetry virtualenvs in select interpreter option

我需要帮助。 VSCode 无论我尝试什么,都永远找不到诗歌 virtualenv 解释器。

使用标准 $ curl 方法安装了 poetry Python 包管理器,如 in the official documentation 所述。

$ poetry new finance-essentials_37-64 开始了一个项目,$ poetry install 安装了 poetry 环境。

所以现在我可以通过以下方式看到我确实有一个虚拟环境:

Jaepil@Jaepil-PC MINGW64 /e/VSCodeProjects/finance_essentials_37-64 $ poetry env list 
>> finance-essentials-37-64-SCQrHB_N-py3.7 (Activated)

并且此 virtualenv 安装在:C:\Users\Jaepil\AppData\Local\pypoetry\Cache\virtualenvs,其中有 finance-essentials-37-64-SCQrHB_N-py3.7 目录。

然而,VSCode 无法在它的 'select interpreter' 命令中找到这个 virtualenv。我只看到一堆 Anaconda 和 Pipenv 环境,但没有看到我刚刚制作的诗歌环境的解释器。

我还按照 here 中的建议将 "python.venvPath": "~/.cache/pypoetry/virtualenvs", 添加到我的 settings.json,但无济于事。 还是不行。

我也尝试了绝对路径,通过将 "python.venvPath": "C:\Users\Jaepil\AppData\Local\pypoetry\Cache\virtualenvs", 添加到相同的设置中,但它也不起作用。

VSCode settings reference 表示它有 python.poetryPath 作为默认值,但它似乎也不起作用。在这种情况下,我应该更改默认值 "poetry" 吗?

python.poetryPath

"poetry"

Specifies the location of the Poetry dependency manager executable, if installed. The default value "poetry" assumes the executable is in the current path. The Python extension uses this setting to install packages when Poetry is available and there's a poetry.lock file in the workspace folder.

我在 Windows 10 pro 64 位系统上安装了 Python 3.7.6。

PS C:\Users\Jaepil> python
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32

您需要在您的设置中设置 "python.venvPath": "C:\Users\Jaepil\AppData\Local\pypoetry\Cache\virtualenvs"(您尝试的是针对 UNIX 的)。

您还可以 https://github.com/microsoft/vscode-python/issues/8372 帮助优先向 Python 扩展添加 Poetry 虚拟环境支持。

您只需输入您的 shell:

poetry config virtualenvs.in-project true

virtualenv 将在项目路径中创建并且vscode 将被识别。


如果您已经创建了项目,则需要 re-create virtualenv 以使其出现在正确的位置:

poetry env list  # shows the name of the current environment
poetry env remove <current environment>
poetry install  # will create a new environment using your updated configuration

您可以将 virtualenvs 文件夹添加到 vs code 全局设置中的 "python.venvFolders"

就像 Windows 那样:

"python.venvFolders": [
    "C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\"
  ]