hudsond7
hudsond7

Reputation: 706

WSL Conda Environment in PyCharm

I'm trying to set up a new dev environment on Windows 10. Let me set the stage with some key points:

I am using Ubuntu through Windows Subsystem for Linux (WSL). I have Anaconda3 installed on WSL. I have PyCharm installed on Windows 10.

I am attempting to use a Conda environment created in the WSL within PyCharm on Windows 10. For some reason I cannot find documentation or guidance on the process.

I have already successfully setup a virtualenv within WSL as a remote interpreter for PyCharm however it will not allow me to do the same with a Conda environment.

Upvotes: 12

Views: 11621

Answers (6)

crdietrich
crdietrich

Reputation: 11

This is now possible, but only available in the Professional version:
https://www.jetbrains.com/help/pycharm/using-wsl-as-a-remote-interpreter.html
These steps worked for me with PyCharm 2023.3.4 Professional, WSL2 running Ubuntu 22.04.4 LTS and miniconda version 24.1.2.

I tried Michael Eaton's solutions first and was not able to navigate past the LocalState directory in the absolute path.

Upvotes: 0

PP_4321
PP_4321

Reputation: 15

There is a way you can use all the conda environments in wsl as well.

  1. Install Anaconda or Miniconda in your wsl
  2. Set the CONDA_ENVS_PATH environment variable in your wsl to where your conda environments reside. (By default it will be /Users/.../anaconda3/envs/)

That's it after you restart your terminal and type conda list env. You can see all your environments in windows.

Incase if you dont know how to custom path for your cond envs: check custom

Upvotes: 0

Tuan Tran
Tuan Tran

Reputation: 51

In your project in Pycharm.

  • Choose File, Setting, Project, Python Interpreter, Add
  • Choose WSL on the left. Linux = your Ubuntu
  • Python interpreter path = home/<your_name>/miniconda3/envs/<your_env>/bin/python3 -- this is the environment you have created in Ubuntu with Conda.

Upvotes: 3

Torge
Torge

Reputation: 63

I haven't been able to confirm that yet, but for me it seems that the direct integration of WSL in PyCharm as Interpreter (like describede here: https://www.jetbrains.com/help/pycharm/using-wsl-as-a-remote-interpreter.html) is only possible when using the Professional Version of PyCharm and not the Community Edition.

Upvotes: 5

Michael Eaton
Michael Eaton

Reputation: 51

This was possible by using the absolute path for the conda interpreter from within PyCharm.

e.g.

C:\Users\winuser\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\wslusr\anaconda3\envs\myenv\bin 

It is now (as of very recently) not.

Upvotes: 5

hudsond7
hudsond7

Reputation: 706

After some trial and error along with contacting JetBrains support, it was determined currently not possible.

My solution to get around this was to have Anaconda installed on both Windows and WSL and then create the Conda environment within Windows. I was then able to activate this environment within WSL with the absolute path to the environment.

Not the best approach but allows for editing in WSL and usage of the interpreter in PyCharm.

Upvotes: 5

Related Questions