VSCode 不显示诗歌 virtualenvs

发布于 2025-01-09 00:32:00 字数 1099 浏览 0 评论 0原文

VSCode 不会在“更改内核”窗口中显示用诗歌创建的 venv。

我尝试了这个线程,但它不起作用。而且这个话题已有 2 年历史了。
尽管我想避免在每个项目的本地文件夹中安装所有依赖项(建议的答案之一),但我仍然尝试了它,但 VSCode 也看不到它(在项目内创建的 .venv 文件夹)。

现在,poetry 将所有 venv 保存在:~/.cache/pypoetry/virtualenvs 中,位于 poetry shell 任何 venv 后面。 为了以防万一,我将其添加到了 settings.json 中

"python.venvPath": "/home/gobsan/.cache/pypoetry/virtualenvs",
"python.venvFolders": [
    "/home/gobsan/.cache/pypoetry/virtualenvs"
  ],

两次,但它是灰色的并且似乎不起作用。

我还尝试将poetry config virtualenvs.path更改为
~/.local/share/pypoetry/venv/bin
~/.local/share/pypoetry/venv
~/.local/share/pypoetry

希望 VSCode 能够看到它,因为它可以看到那里的东西 输入图片此处描述

我的主要目标是能够在 Jupyter 内查看不同的 venv 并在它们之间进行切换。将诗歌 venvs 切换为 python 脚本没有问题。
感谢您的帮助。

附注通过 wsl2 工作

VSCode wouldn't show venvs created with poetry in "change kernel" window.

I tried this thread but it didn't work. As well as the topic being 2 years old.
Eventhough I would like to avoid installing all the dependencies in local folder for each project (one of the suggested answers), I still tried it but VSCode doesn't see it either (.venv folder created inside the project).

Right now poetry saves all the venvs in: ~/.cache/pypoetry/virtualenvs after poetry shell any of the venvs. I added it to settings.json with

"python.venvPath": "/home/gobsan/.cache/pypoetry/virtualenvs",
"python.venvFolders": [
    "/home/gobsan/.cache/pypoetry/virtualenvs"
  ],

2x times just in case, but it is greyed out and doesn't seem to work.

I have also tried to change poetry config virtualenvs.path to
~/.local/share/pypoetry/venv/bin
~/.local/share/pypoetry/venv
~/.local/share/pypoetry

hoping VSCode will see it since it can see something there
enter image description here

My main goal is to be able to see and switch between different venvs inside Jupyter. Switching poetry venvs for python scripts is no problem.
Thank you for any help.

ps. working through wsl2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

秋叶绚丽 2025-01-16 00:32:00

您应该以正斜杠结束路径,例如 "/home/gobsan/.cache/pypoetry/virtualenvs/"
我只是在研究 Poetry 和 VSCode,最终也做了这个。

这是我自己的路径设置更新后我的解释器是什么样的

You should end your path with a forward slash, like "/home/gobsan/.cache/pypoetry/virtualenvs/".
I was just researching Poetry and VSCode and ended up doing this as well.

Here's my own path and what my interpreter looks like after the settings update

永言不败 2025-01-16 00:32:00

将 poetry.toml 添加到您的项目根目录并包含以下内容:

[virtualenvs]
create = true
in-project = true

这将在您的项目根目录中创建虚拟环境,而不是 ~/Library/Caches/pypoetry/virtualenvs (mac):

$ poetry shell

安装依赖项:

$ poetry install

现在,选择内核,您将在项目根目录中找到名为 .venv 的诗歌虚拟环境。

Add poetry.toml to your project root with content:

[virtualenvs]
create = true
in-project = true

This will create the virtual environment in your project root instead of ~/Library/Caches/pypoetry/virtualenvs (mac):

$ poetry shell

Install the dependencies:

$ poetry install

Now, selecting the kernel, you will find your poetry virtual environment in the project root as .venv.

倒带 2025-01-16 00:32:00

VS Code 中 Python 扩展的设置已更改。将日期的 python.pythonPath 设置(您的可能是 python.venvPath)更改为 后,我能够再次为我的解释器/ipynb 内核选择 Poetry 虚拟环境VS Code settings.json 文件中的 python.defaultInterpreterPath

我不知道更改此设置是否允许 VS Code 自动获取 CLI 中 poetry env info --path 下列出的其他 Poetry 虚拟环境选项。这里的指南希望对此有用: https:// /code.visualstudio.com/docs/python/environments#_manually-specify-an-interpreter

{
    "python.defaultInterpreterPath": "/Users/myname/Library/Caches/pypoetry/virtualenvs/projectname-randomnumbers-py3.9/bin/python",
}

(我的工作计算机是 Mac)

The settings have changed for the Python extension in VS Code. I was able to select my Poetry virtual environment for my interpreter/ipynb kernel again after changing the dated python.pythonPath setting (yours might be python.venvPath) to python.defaultInterpreterPath in the VS Code settings.json file.

I don't know if changing this setting will allow VS Code to automatically pick up other Poetry virtual environment options listed under poetry env info --path in your CLI. The guidance here will hopefully be of use for that: https://code.visualstudio.com/docs/python/environments#_manually-specify-an-interpreter

{
    "python.defaultInterpreterPath": "/Users/myname/Library/Caches/pypoetry/virtualenvs/projectname-randomnumbers-py3.9/bin/python",
}

(my work computer is a Mac)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文