VSCode在选择解释器选项中不显示虚拟对象

2024-05-19 00:20:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要帮助。无论我做什么尝试,VSCode都永远找不到虚拟的解释器

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

通过$ poetry new finance-essentials_37-64启动了一个项目,使用$ poetry install安装了Poethy环境

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

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无法在其“选择解释器”命令中找到此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

Tags: installtheinpoetry环境virtualenvvirtualenvsvscode
3条回答

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

与Windows类似:

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

您只需在shell中键入:

poetry config virtualenvs.in-project true

virtualenv将在项目路径内创建,vscode将识别


如果您已经创建了项目,则需要重新创建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

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

你也可以👍 https://github.com/microsoft/vscode-python/issues/8372帮助确定向Python扩展添加虚拟环境支持的优先级

相关问题 更多 >

    热门问题