powershellcondawindows-subsystem-for-linuxpath-variables

`conda --version` command not working in Powershell or WSL bash


I have Anaconda installed in Windows 11 under C:\Users\user\anaconda3. I also have WSL. I am trying to run conda --version in both Powershell and the WSL terminal and in both cases I am getting an error that conda is not a command.

In Windows I added C:\Users\user\anaconda3 to my user path variables and that did not work.

I have a .bashrc file in both my Linux home directory and in C:\Users\user. In the Linux file I added the line export PATH="/mnt/c/Users/user/anaconda3:$PATH" and typed source .bashrc in the WSL terminal while in the Linux home directory. In the Windows .bashrc file I added the line export PATH="anaconda3:$PATH". Neither of those worked.

I looked at this solution: Windows Subsystem for Linux - conda: command not found. I tried the solution of running conda.exe in both terminals (Powershell and bash) and got the same error. I tried the solution of running .anaconda3/bin/conda init and not only does my .anaconda3 not have a bin directory, running that command gives me the same error in both terminals. I tried the solution to navigate to home/{your user name}/anaconda3/bin but Anaconda is installed in Windows, not Linux, and my anaconda3 doesn't have a bin directory.

I tried Googling whether I need to just install Anaconda in WSL and I was only able to find this page: https://www.reddit.com/r/learnpython/comments/1ckbbya/what_would_happen_if_i_installed_anaconda_on_wsl/#:~:text=Installing%20Anaconda%20on%20WSL%202,stick%20with%20the%20native%20install., which doesn't really say explicitly that I have to install Anaconda in WSL, especially since I want to run conda while in a Windows directory.

I tried following the instructions to install Anaconda in WSL at this site: https://gist.github.com/kauffmanes/5e74916617f9993bc3479f401dfec7da. I added export PATH="anaconda3:$PATH" to the .bashrc file in my Linux home directory and ran source .bashrc while in that directory. Then tried running conda --version while in that directory in bash and got the same error.


Solution

  • OK, I fixed it with WSL! I just needed to add export PATH=~/anaconda3/bin:$PATH to the .bashrc file in my Linux home directory (it looks like when I tried this before I typed it without specifying the home directory). Then while in the home directory I ran source .bashrc, then conda init. Now it works.

    One additional note, I found it's not recommended to add conda to PATH. For what to do instead, see this page: https://docs.anaconda.com/working-with-conda/reference/faq/.