VSCode 不显示诗歌 virtualenvs
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
我的主要目标是能够在 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该以正斜杠结束路径,例如
"/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
将 poetry.toml 添加到您的项目根目录并包含以下内容:
这将在您的项目根目录中创建虚拟环境,而不是
~/Library/Caches/pypoetry/virtualenvs
(mac):安装依赖项:
现在,选择内核,您将在项目根目录中找到名为
.venv
的诗歌虚拟环境。Add
poetry.toml
to your project root with content:This will create the virtual environment in your project root instead of
~/Library/Caches/pypoetry/virtualenvs
(mac):Install the dependencies:
Now, selecting the kernel, you will find your poetry virtual environment in the project root as
.venv
.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(我的工作计算机是 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 bepython.venvPath
) topython.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(my work computer is a Mac)