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?
(See question also in StackOverflow: https://stackoverflow.com/posts/70205270/edit)
====================================================
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:

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:

(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?
(See question also in StackOverflow: https://stackoverflow.com/posts/70205270/edit)
Please sign in to leave a comment.
We don't support virtual environments inside WSL. One can configure a WSL interpreter and point it to a python executable inside the virtual environment, as you mentioned, but it won't be treated as an actual virtual environment.
There is a related ticket in our issue tracker about that https://youtrack.jetbrains.com/issue/PY-32853
Sergey Karpov, if I could have configured it as e "regular" interpreter that would have also been fine, but as I described above, that does not seem to be an option. As I mentioned, the executable there doesn't show.
Yeah, this seems like a pretty big missing feature. I'm in need of this too.
Please add virtualenv to WSL, this is a basic feature for Python and tonns of people work in WSL. I cannot run my scripts defined in
without putting
at the end of the file
@Sergey Karpov Has this bug been resolved? According to the docs, I should be able to activate a virtual env. in the WSL terminal. What is the current status of this issue?
Thanks for pointing out this problem, I have the exact same need.
Has this been resolved? I still don't seem to be able to get the poetry environment on WSL.
Not yet, please vote for
https://youtrack.jetbrains.com/issue/PY-52688/Support-Poetry-Pipenv-interpreter-creation-over-a-remote-target-WSL-SSH-etc.
in order to be updated on the progress.