TL;DR:无法使用 WSL 中的现有 Poetry 环境在 PyCharm (Windows) 上配置 Python 解释器。当尝试设置 Poetry 环境路径时Add Python Interpreter > Poetry Environment > Existing Environment
,所需的 Python 可执行文件根本不显示。我究竟做错了什么?
=================================================== ==
Details:
我在 Windows 11 上使用 PyCharm Pro 2021.3,Python 在 WSL2 (Ubuntu 20.04) 上运行。我正在尝试为我在 WSL2 上创建的现有 Poetry 环境添加一个 python 解释器,但它似乎不起作用。
PyCharm's current support of Poetry is via adopting https://www.jetbrains.com/pycharm/whatsnew/#poetry-support this plugin https://plugins.jetbrains.com/plugin/14307-poetry. From what I could gather from the plugin's official documentation https://plugins.jetbrains.com/plugin/14307-poetry, 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:
为了找到该环境的路径,我运行“诗歌环境信息 https://python-poetry.org/docs/managing-environments/#displaying-the-environment-information",它给出了以下模式的路径:
\\wsl$\Ubuntu-20.04\home\$USER$\.cache\pypoetry\virtualenvs\my-pretty-project-<some-hash>-py3.8\
跑步时which python
在环境中,我看到 python 可执行文件位于:
\\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 https://stackoverflow.com/questions/65413557/using-pycharm-professonal-with-wsl2-as-python-interpreter-does-not-have-access question. However - and similarly to what described in said question https://stackoverflow.com/questions/65413557/using-pycharm-professonal-with-wsl2-as-python-interpreter-does-not-have-access - 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:
(遗憾的是,上述问题中描述的解决方案不适用于我的问题,因为我已经在使用 Poetry 环境的补丁了)。
我该怎么做才能使这项工作成功?