3

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

Oleg Peregudov
  • 137
  • 2
  • 8

3 Answers3

4

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

Rantunes
  • 81
  • 3
2

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)

BLT
  • 415
  • 3
  • 9
0

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.

diogo
  • 525
  • 1
  • 7
  • 12