3
votes

I'm trying to use python interpreter in wsl to make virtual environment, buy it doesn't show any python file.

and I used where python3 to find interpreter. It says /usr/bin/python3 but as you can see it shows nothing in pycharm.

enter image description here

I also tried uninstalling and reinstalling pycharm and it didn't work.

also when I create a virtual env from wsl terminal using virtualenv -p python3 venv I can't import that in pycharm because it doesn't recognize python in ~/venv/bin/...

3
did you try the WSL button under vagrant? - Mogi
yes. that is main python interpreter and not a virtual env - amirhosein arabhaji
I am not familiar with WSL, but I do use SSH interpreter, and with my experience I know it doesn't really support it in pycharm. The workaround I use is to first set up new venv manually on my server, and then set it as the interpreter through pycharm. If it helps you I'll post it as an answer - Mogi
thanks if you do. I think it can be done by set up a venv on wsl and then set it as interpreter through ssh, as you told. - amirhosein arabhaji

3 Answers

4
votes

Sadly, Virtual Environments are not yet supported in Pycharm with WSL. See the docs here.

Excerpt: "Note that with WSL you cannot create virtual environments: all packages you install will be added to the corresponding system interpreter. You will be asked to enter your sudo password"

If I absolutely need to code against a library within Ubuntu (such as Apache Pulsar), I use Linux Pycharm running an XSession to XFCE, running withing WSL. It works very well and you will find lots of articles to achieve this with a Google Search.

2
votes

I am not familiar with using WSL through PyCharm, but I do use an interpreter on remote server thourgh SSH.
With my experience I know PyCharm doesn't support creating a new venv environment from the IDE on the remote server.

The workaround I use is to first set up new venv manually within the server, and then when I set up the project interpreter in PyCharm I set the interpreter path to the relevant venv path in the server.
So I suggest the same thing- first create a new venv on the WSL environment and then set the path of the venv as the project interpreter (through WSL no through remote server)

2
votes

You can set up venv inside wsl:

python3 -m venv /usr/venv/project1

And add this to pycharm: image