Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Configure Poetry Environments in Pycharm With Windows + WSL2?

TL;DR: can't configure a Python Interpreter on PyCharm (Windows) using an existing Poetry environment in WSL. When trying to set the Poetry environment path under Add Python Interpreter > Poetry Environment > Existing Environment, the needed Python executable simply does not show. What am I doing wrong?

====================================================

Details:

I'm using PyCharm Pro 2021.3 on Windows 11, with Python running on WSL2 (Ubuntu 20.04). I am trying to add a python interpreter for an existing Poetry environment I created on WSL2, and it just does not seem to work.

PyCharm's current support of Poetry is via adopting this plugin. From what I could gather from the plugin's official documentation, in order to define an interpreter with an existing Poetry environment, I go to Python Interpreter > Add > Poetry Environment, choose Existing environment, and put in the path to that specific environment: enter image description here

In order to find the path to that environment, I run "poetry env info", which gives a path in the following pattern:

\\wsl$\Ubuntu-20.04\home\$USER$\.cache\pypoetry\virtualenvs\my-pretty-project-<some-hash>-py3.8\

When running which python in the environment, I see the python executable is at:

\\wsl$\Ubuntu-20.04\home\$USER$\.cache\pypoetry\virtualenvs\my-pretty-project-<some-hash>-py3.8\bin\python

However - when I browse to that location in PyCharm, the Python file simple does not show. The bin directory appears as empty - as also described in this question. However - and similarly to what described in said question - if I try to redefine the default interpreter path for WSL to be the path to that Poetry environment, the Python executable is there and kicking: enter image description here

(The solution described in the aforementioned question, sadly, does not work for my problem, as I am already using the patch to the Poetry environment).

What can I do to make this work?

like image 841
aon Avatar asked Dec 10 '25 06:12

aon


1 Answers

I "solved" it by setting Add Python interpreter => WSL => Python interpreter path: to

/home/user/.cache/pypoetry/virtualenvs/project-name-1yjHsXUg-py3.10/bin/python

The path above is the poetry environment obtained by

$ poetry shell
$ which python
like image 152
droidballoon Avatar answered Dec 11 '25 20:12

droidballoon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!