0

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.

2 Answers 2

0
  1. you cannot run a conda installation made under windows in WSL, because that is a linux subsystem and cannot natively run windows applications. You will need to download and install anaconda to WSL seperately.

  2. making conda available to run from powersehll is not just a matter of adding a directory to PATH, the correct approach is to initialize conda for a certain terminal via conda init. First, remove your modifications to PATH, then open the Anaconda (Powershell) Prompt or Anaconda Command Prompt which you can find via the search function in the start menu. From there type conda init powershell. Then try running conda commands from a "normal" powershell session. Alternatively, you can use the Anaconda (Powershell) Prompt in all cases that you do need conda. It is nothing more than a normal powershell session with an additional initialization step for conda commands

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for getting to my question! As my post says, I tried installing Anaconda in Linux. conda init worked in Powershell and now everything's working correctly there, thanks! However, conda init does not work in the WSL terminal, I am getting the same error that conda is not a command.
Update: I went to this site: docs.anaconda.com/working-with-conda/reference/faq and navigated to anaconda3/bin in my WSL terminal. The site says to navigate to the subdirectory activate, but mine doesn't have activate as a directory, instead it's a file. I tried running source activate and that does not work.
Re 1: It may be surprising, but you can invoke Windows binaries from WSL, as long as you include the .exe extension in the invocation; see dmartinsdesa.medium.com/…. E.g., invoking powershell.exe -c "'hi there'" from WSL Bash works just fine.
0

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/.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.