Reputation: 3911
I need help. VSCode will NEVER find poetry virtualenv interpreter no matter what I try.
Installed poetry Python package manager using a standard $ curl
method as explained in the official documentation.
Started a project by $ poetry new finance-essentials_37-64
, installed poetry environment with $ poetry install
.
So now I can see that I indeed have a virtual environment by:
Jaepil@Jaepil-PC MINGW64 /e/VSCodeProjects/finance_essentials_37-64 $ poetry env list
>> finance-essentials-37-64-SCQrHB_N-py3.7 (Activated)
and this virtualenv is installed at: C:\Users\Jaepil\AppData\Local\pypoetry\Cache\virtualenvs
, which has finance-essentials-37-64-SCQrHB_N-py3.7
directory.
However, VSCode is unable to find this virtualenv in its 'select interpreter' command. I only see a bunch of Anaconda and Pipenv environments but not the poetry environment's interpreter that I've just made.
I also added "python.venvPath": "~/.cache/pypoetry/virtualenvs",
to my settings.json
as suggested in here, but to no avail.
Still doesn't work.
I also tried an absolute path, by adding "python.venvPath": "C:\\Users\\Jaepil\\AppData\\Local\\pypoetry\\Cache\\virtualenvs",
to the same settings, but it also doesn't work.
VSCode settings reference states that it has python.poetryPath
as a default but it doesn't seem to work either. Should I change the default value "poetry"
in this case?
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.
I'm on Windows 10 pro 64bit & Has Python 3.7.6 installed on the system.
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
Upvotes: 196
Views: 145832
Reputation: 851
An alternative is to run
poetry run jupyter lab
And use existing jupyter server option in vscode.
Upvotes: 0
Reputation: 5767
This is now resolved. See vscode-python Issue #16232
You need to remove your old environment
Set poetry config virtualenvs.in-project false
(if you had this set to true before)
poetry install
Reload VSCode and when you next go to "Select Interpreter" and search for "poetry" it should show up.
Upvotes: 2
Reputation: 2025
An alternative to the other solution is to simply select the poetry virtual environment folder. VSCode is able to find it automatically, and by doing so, it should find all the dependencies together. To follow the steps, refer to the picture below:
1. Click on the interpreter in the bottom menu.
2. From the list that appears, choose your poetry virtual env e.g .cache/virtualenv.
By following this method, you won't need to use a local virtual environment.
Upvotes: -1
Reputation: 5203
You just need to type in your shell:
poetry config virtualenvs.in-project true
The virtualenv will be created inside the project path and vscode will recognize. Consider adding this to your .bashrc
or .zshrc
.
If you already have created your project, you need to re-create the virtualenv to make it appear in the correct place:
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
Upvotes: 486
Reputation: 460
This blog post summarize nice in one commands :
poetry env info --path | pbcopy
https://www.markhneedham.com/blog/2023/07/24/vscode-poetry-python-interpreter/
Upvotes: 10
Reputation: 301
You can add your virtualenvs folder to "python.venvFolders"
in vs code global settings.
Like that for Windows:
"python.venvFolders": [
"C:\\Users\\User\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\"
]
to get the path you run poetry config virtualenvs.path
as @Aipi has commented
Upvotes: 20
Reputation: 495
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.
Note: My work computer is a Mac but I expect this should work for Windows. To find the ~path, enter poetry env info --path
in your CLI under the appropriate project folder, then tack on the subdirectory info where Python is installed. On MacOS/Linux, this ends with "/bin/python"; on Windows, "python.exe". https://code.visualstudio.com/docs/python/environments#_manually-specify-an-interpreter for more info.
{
"python.defaultInterpreterPath": "/Users/myname/Library/Caches/pypoetry/virtualenvs/projectname-randomnumbers-py3.9/bin/python",
}
Upvotes: 16
Reputation: 16080
You need to set "python.venvPath": "C:\\Users\\Jaepil\\AppData\\Local\\pypoetry\\Cache\\virtualenvs"
in your settings (the one you tried is for UNIX).
You can also 👍 https://github.com/microsoft/vscode-python/issues/8372 to help prioritize adding Poetry virtual environment support to the Python extension.
Upvotes: 63