WSL Conda Environment in PyCharm

Viewed 5561

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.

5 Answers

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.

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.

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.

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

Related