0

Goal: get conda working in WSL 2.

conda works in Git Bash, but not in WSL 2.

Anaconda3:

C:\Users\dabell\Anaconda3

WSL 2:

danielbellhv@PF2DCSXD:/$ cat ~/.bashrc
. /c/Users/dabell/Anaconda3/etc/profile.d/conda.sh
. "C:/Users/dabell/Anaconda3/etc/profile.d/conda.sh"
export PATH="C:/Users/dabell/Anaconda3/condabin:$PATH"
danielbellhv@PF2DCSXD:/$ conda info
conda: command not found
danielbellhv@PF2DCSXD:/$ conda init
conda: command not found
danielbellhv@PF2DCSXD:/$ ./anaconda3/Scripts/conda.exe init
bash: ./anaconda3/Scripts/conda.exe: No such file or directory
danielbellhv@PF2DCSXD:/$ export PATH=~/anaconda/bin:$PATH
danielbellhv@PF2DCSXD:/$ conda info
conda: command not found

Git Bash:

HDS+dabell@PF2DCSXD MINGW64 ~
$ conda info

     active environment : base
    active env location : C:\Users\dabell\Anaconda3
            shell level : 1
       user config file : C:\Users\dabell\.condarc
 populated config files :
          conda version : 4.12.0
    conda-build version : 3.21.8
         python version : 3.9.12.final.0
       virtual packages : __win=0=0
                          __archspec=1=x86_64
       base environment : C:\Users\dabell\Anaconda3  (writable)
      conda av data dir : C:\Users\dabell\Anaconda3\etc\conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : C:\Users\dabell\Anaconda3\pkgs
                          C:\Users\dabell\.conda\pkgs
                          C:\Users\dabell\AppData\Local\conda\conda\pkgs
       envs directories : C:\Users\dabell\Anaconda3\envs
                          C:\Users\dabell\.conda\envs
                          C:\Users\dabell\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.12.0 requests/2.27.1 CPython/3.9.12 Windows/10 Windows/10.0.19041
          administrator : True
             netrc file : None
           offline mode : False

(base)
HDS+dabell@PF2DCSXD MINGW64 ~
$ cat ~/.bashrc
. /c/Users/dabell/Anaconda3/etc/profile.d/conda.sh
(base)

DanielBell99
  • 896
  • 5
  • 25
  • 57

1 Answers1

1

To use conda in WSL you first have to install it in WSL, Windows & Linux, even in WSL, still require two separate conda installations. You'll probably encounter less issues if you pick miniconda for WSL, export your existing conda evironment(s) in Windows:

(geopy) PS C:\> conda env export --from-history > environment.yml

And use the resulting environment.yml file(s) to re-create it/those in WSL:

$ conda env create -f environment.yml
margusl
  • 7,804
  • 2
  • 16
  • 20
  • I'm not sure a conda environment.yml file from Windows will simply work in WSL / Linux. Have you tried this? [This other question](https://stackoverflow.com/q/39280638/1256347) deals with this issue for example. – Saaru Lindestøkke Jun 29 '22 at 22:24
  • @SaaruLindestøkke, `conda env export --from-history` should list only explicitly installed packages and linked conda doc does use it in context of _Exporting an environment file across platforms_ . I actually just tested with my geospatial environment, some packages were pinned, export in Win, `env create` in WSL (Ubuntu 20.04), freshly installed miniconda. Solving environment took its time but no issues during package download and installation, env seems fine. – margusl Jun 29 '22 at 23:05
  • Ah ok, good to know that works. Downside of `--from-history` is that `pip` packages are not included, while they are in the regular `conda env export`. – Saaru Lindestøkke Jun 29 '22 at 23:08
  • You could also omit the windows build information while keeping the pip installed packages with `conda env export --no-builds | findstr -v "prefix" > environment.yml` (or `grep` instead of `findstr` if not on win or on alias). Should then work platform-agnostic as it gets to re-resolve package builds specific to the OS. – Huug. Jun 30 '22 at 12:42