1

I am having problems with Anaconda and Bash working together on my Windows 10 computer. I installed Anaconda, added it to the PATH variable, ran init bash. But I always get the same error when I try using the conda command, claiming it cannot find conda.exe:

conda activate my_env
bash: /cygdrive/c/Users/Bennji/anaconda3/Scripts/conda.exe: No such file or directory

I ran into the same issue last week and only solved it after deleting all my environments, and uninstalling anaconda and bash, and then reinstalling an recreating everything. So that is not a sustainable solution for me, as creating some of the environments takes quite some time. Also, I would like to understand what happened, to prevent this from reoccurring.

Additionally, the conda command works fine in cmd and powershell.

I should add that I have only a very basic understanding of all this, as I am quite new to terminals, conda, environments, and python. Any help would be greatly appreciated.

I tried with my limited knowledge to solve the issue, but didn't find a solution. The where conda command shows me the location just fine.

$ where conda
C:\Users\Bennji\anaconda3\Library\bin\conda.bat
C:\Users\Bennji\anaconda3\Scripts\conda.exe
C:\Users\Bennji\anaconda3\condabin\conda.bat

My PATH variable includes these lines at the beginning

C:\Users\Bennji\anaconda3\Scripts;
C:\Users\Bennji\anaconda3;
C:\Users\Bennji\anaconda3\Library\mingw-w64\bin;
C:\Users\Bennji\anaconda3\Library\usr\bin;
C:\Users\Bennji\anaconda3\Library\bin;

By typing $ C:/Users/Bennji/anaconda3/Scripts/conda.exe, I can run things such as init bash:

$ C:/Users/Bennji/anaconda3/Scripts/conda.exe init bash
no change     C:\Users\Bennji\anaconda3\Scripts\conda.exe
no change     C:\Users\Bennji\anaconda3\Scripts\conda-env.exe
no change     C:\Users\Bennji\anaconda3\Scripts\conda-script.py
no change     C:\Users\Bennji\anaconda3\Scripts\conda-env-script.py
no change     C:\Users\Bennji\anaconda3\condabin\conda.bat
no change     C:\Users\Bennji\anaconda3\Library\bin\conda.bat
no change     C:\Users\Bennji\anaconda3\condabin\_conda_activate.bat
no change     C:\Users\Bennji\anaconda3\condabin\rename_tmp.bat
no change     C:\Users\Bennji\anaconda3\condabin\conda_auto_activate.bat
no change     C:\Users\Bennji\anaconda3\condabin\conda_hook.bat
no change     C:\Users\Bennji\anaconda3\Scripts\activate.bat
no change     C:\Users\Bennji\anaconda3\condabin\activate.bat
no change     C:\Users\Bennji\anaconda3\condabin\deactivate.bat
no change     C:\Users\Bennji\anaconda3\Scripts\activate
no change     C:\Users\Bennji\anaconda3\Scripts\deactivate
no change     C:\Users\Bennji\anaconda3\etc\profile.d\conda.sh
no change     C:\Users\Bennji\anaconda3\etc\fish\conf.d\conda.fish
no change     C:\Users\Bennji\anaconda3\shell\condabin\Conda.psm1
no change     C:\Users\Bennji\anaconda3\shell\condabin\conda-hook.ps1
no change     C:\Users\Bennji\anaconda3\Lib\site-packages\xontrib\conda.xsh
no change     C:\Users\Bennji\anaconda3\etc\profile.d\conda.csh
no change     C:\Users\Bennji\.bash_profile
No action taken.

But environments still don't work as intended (yet they do work in powershell and cmd):

$ C:/Users/Bennji/anaconda3/Scripts/conda.exe activate my_env

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

The only progress I made is from this related question: When I type "bash" into my bash terminal after opening it, it does recognize the conda command. but it still tells me to initalize my shell, yet when doing that, it yields the lines above, saying it took no action (and it also doesn't fix the issue, not even after restarting my shell). Also, why do I need to tell it to use bash all of a sudden? I didn't have to before.

Regarding Charles's comment: The type command yields the following:

$ type conda
conda is hashed (/c/Users/Bennji/anaconda3/Scripts/conda)

I'm not sure what to make of that, though. After all, conda.exe exists at the location C:/Users/Bennji/anaconda3/Scripts/

Bennji
  • 11
  • 4
  • Note that "recognize the conda command" can mean two different things: It can mean you have the `conda` executable/wrapper in your PATH, or it can mean you have the `conda` shell function defined. The latter is what you need for `activate` to work. Don't just check whether `conda` emits an error: if it's not emitting an error, you need to determine _why_ it's not determining an error, and thus whether it's just installed somewhere your shell can find it, or actually _configured_ for your shell. In bash, `type conda` will give you the info needed to answer that. – Charles Duffy Jul 13 '23 at 13:17
  • I wouldn't be surprised at all if `type conda` in your particular case would tell you that `conda` is an alias to `/cygdrive/c/Users/Bennji/anaconda3/Scripts/conda.exe` -- if that's true, and no such file actually exists, then there's your problem, which can at that point be resolved by deleting whatever you've got in your config files setting up that alias. – Charles Duffy Jul 13 '23 at 13:19
  • `where` does a PATH search, so it doesn't know anything at all about aliases or functions; it's not a useful tool for understanding why bash does what it does. Stick to `type` or `command -v`. – Charles Duffy Jul 13 '23 at 13:20
  • Thank you for the hint. I have added the result of type conda to the question. However, I am unsure what to make of that, as conda.exe exists at that location. – Bennji Jul 13 '23 at 13:36
  • That's telling you it's finding conda-the-executable, which means you don't have conda-the-shell-function installed. – Charles Duffy Jul 13 '23 at 13:42
  • See [How does `conda activate` change current bash environment?](https://stackoverflow.com/questions/65589737/how-does-conda-activate-change-current-bash-environment) for some background on why those are different things. There's a shell script you need to source to define the function. – Charles Duffy Jul 13 '23 at 13:44
  • ...if your version of conda is new enough, `conda shell.bash hook` will write the shell function to stdout, which means you can install that function by running `eval "$(conda shell.bash hook)"`. – Charles Duffy Jul 13 '23 at 13:46
  • Okay, thank you so much, then I have at least a bit of a better idea of what the issue is. Sorry if I am missing the obvious here, but `eval "$(conda shell.bash hook)"` is prompting that same message `bash: /cygdrive/c/Users/Bennji/anaconda3/Scripts/conda.exe: No such file or directory` Which seems to make some sense? And including the full path to the exe also does not work. – Bennji Jul 13 '23 at 14:07
  • Bash doesn't run exe files, anyway. Why can't you just use Powershell/CMD? Why do you even need Cygwin over WSL2? – OneCricketeer Jul 13 '23 at 14:13
  • `set -x` will enable trace-level logging, if you run it before doing the `eval`. I don't do Windows, though, so not well-placed to try to reproduce the issue myself. – Charles Duffy Jul 13 '23 at 14:40
  • I use bash simply because when I took my first steps with Python and everything, I learned it with bash as my default shell. And it used to work fine until just recently. I have no idea about cygwin or wsl2 and their pros and cons. So I probably do not need any of them over the other. But I would like my regular setup to work if possible. I am no expert in any of this, I just want to have my setup, so that I can do my Python coding and deal with environments with as little friction as possible. If there is a benefit to a different setup, I would not mind trying it out. – Bennji Jul 13 '23 at 14:47
  • Okay, so with set -x, I get a whole ton of output. Then eval "$(conda shell.bash hook)" also generates a lot of stuff, starting with sth that looks like the same error again `++ conda shell.bash hook ++ local cmd=shell.bash ++ case "$cmd" in ++ __conda_exe shell.bash hook ++ /cygdrive/c/Users/BenjaminBotor/anaconda3/Scripts/conda.exe shell.bash hook bash: /cygdrive/c/Users/BenjaminBotor/anaconda3/Scripts/conda.exe: No such file or directory` and then a lot more. I have no clue how to interpret the output. – Bennji Jul 13 '23 at 14:54

0 Answers0