5

I'm using Windows 10 and recently installed Windows Subsystem for Linux. Anaconda was already installed on my PC at that point.

When I try to run conda commands on Bash on Ubuntu on Windows I get the following error:

$ conda conda: command not found

Other related answers, such as this or this suggest adding

C:\Users\«user»\Anaconda3\Scripts
C:\Users\«user»\Anaconda3

to $PATH. But as you can see below, both are already included (I didn't add them manually):

$ echo $PATH | tr ':' '\n'
...
/mnt/c/Users/«user»/Anaconda3
/mnt/c/Users/«user»/Anaconda3/Scripts
/mnt/c/Users/«user»/Anaconda3/Library/bin
...

The following conda files are available in Anaconda3/Scripts:

conda.exe
conda-env.exe
conda-env-script.py
conda-script.py
conda-server.exe
conda-server-script.py

The commands work just fine in both PowerShell and cmd.

What am I missing?

[EDIT]: Corrected second URL and changed user to < user > in Anaconda3 paths above.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
Marco
  • 313
  • 1
  • 2
  • 11
  • In your path the file is in `…/Users/Marco/…`, but you tell us that it is in `…/Users/user/…`. – ctrl-alt-delor Dec 16 '18 at 20:02
  • @ctrl-alt-delor: user was meant as placeholder for the username. Changed it to to make it clearer. – Marco Dec 16 '18 at 20:18
  • 1
    Try to run `conda.exe` instead of `conda`. – Poshi Dec 17 '18 at 00:29
  • @Poshi: That did it. In other words the alias was missing. Added it to my ~/.bashrc. I guess it makes sense because Anaconda was installed before WSL. What if I had installed Anaconda on Windows after activating WSL? would it have created an alias automatically? Anyway, if you post that as an answer I'll accept it. – Marco Dec 17 '18 at 01:17
  • @MarcoLeal I changed the other bit, to make it consistent – ctrl-alt-delor Dec 17 '18 at 08:42

3 Answers3

16

Try to run conda.exe instead of conda.

Windows assume .exe marks a file as executable, and ignores that extension when looking for the binary. Linux uses a flag, so any file can be an executable, and you need to provide the full name because there is no assumption on the extension.

Poshi
  • 5,332
  • 3
  • 15
  • 32
  • 1
    Yes in Unix a name is a name. In windows you specify the implementation (`.exe`, `.bat`, `.com`, `.py`, …. In Unix we don't leak the implementation (we don't use file extensions. If we do it is just part of the name). – ctrl-alt-delor Dec 17 '18 at 08:46
5

Run conda init

.anaconda3/bin/conda init 
.miniconda/bin/conda init
  • 2
    For me `conda init zsh` fixed my problem as I had not realized I broke conda by switching from bash to zsh – xyzzyqed Mar 09 '21 at 18:20
0

To add conda to Windows Subsystem Linux, this is the correct way:

curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
export PATH=$PATH:/miniconda3/bin

You will need to restart WSL for the env path to work.