Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/...

like image 416
amirhosein arabhaji Avatar asked Sep 27 '20 10:09

amirhosein arabhaji


People also ask

Can PyCharm work with WSL?

If you have any directory with some Python files in \\wsl$ , you can open this directory in PyCharm. The IDE will create a project and suggest creating a WSL-based interpreter.

How do I enable virtual env in PyCharm?

Set an existing virtual environmentPress Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter. icon and select Show All. Select the target environment from the list and click OK to confirm your choice.

Does PyCharm support virtual environments with WSL?

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"

Does PyCharm support virtualenv-P Python3 venv?

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/... Show activity on this post. Sadly, Virtual Environments are not yet supported in Pycharm with WSL. See the docs here.

How to create a venv environment from the IDE in PyCharm?

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.

Why does PyCharm say the environment is invalid?

If PyCharm warns you about an Invalid environment, the specified Python binary cannot be found in the file system, or the Python version is not supported. Check the Python path and install a new version, if needed. You can create as many virtual environments as required. To easily tell them from each other, use different names.


Video Answer


3 Answers

You can set up venv inside wsl:

python3 -m venv /usr/venv/project1

And add this to pycharm: image

like image 61
Roman Avatar answered Oct 05 '22 23:10

Roman


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.

like image 24
Adrian Avatar answered Oct 06 '22 01:10

Adrian


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)

like image 35
Mogi Avatar answered Oct 06 '22 01:10

Mogi