'Can't make a virtual env in PyCharm using a WSL Python interpreter

I'm trying to use a Python interpreter in WSL to make virtual environments, buy it doesn't show any Python file.

I used where python3 to find the 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/...



Solution 1:[1]

You can set up venv inside wsl:

python3 -m venv /usr/venv/project1

And add this to pycharm: image

Solution 2:[2]

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.

Solution 3:[3]

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)

Solution 4:[4]

What I do, is create a virtual env manuall python3 -m venv venv and then in PyCharm I set the python interpreter from the virtual env created. It works, the only painful point is when you add mopre packages, you would need to invalidate caches.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DaveL17
Solution 2 Adrian
Solution 3 Mogi
Solution 4 Andrés Cevallos prado