conda: command not found – possible fixes

conda is an open source, cross-platform package and environment manager which runs on multiple platforms including Windows, Linux and macOS.

It was originally created for installing and managing multiple versions of Python packages, but can be extended to support many other languages such as R, Ruby, Lua, JavaScript, etc.

If you're already familiar with Python, imagine conda as pip and virtualenv combined.

This article is going to show you how to fix conda "command not found" (in Linux and macOS) or "not recognized as internal or external command" in Windows.

Different form of the same error

Any OS has some kind of system variable containing the paths where they would find commonly-used executables, so that they can allow you to run these without specifying the full path. That system variable is called PATH or $PATH.

Let's suppose the PATH contains /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games.

When you run, for example, conda, the OS is going to search for conda inside one of these path, if it's found, it will be executed, if not, "command not found" error will be spit out.

The error message may look different across operating system and terminals. Usually on Linux, it could be bash: conda: command not found. On macOS with zsh, the error is zsh: command not found: conda. On Windows, conda not recognized as internal or external command would be displayed.

macos conda command not found

Please note that normally you would have to run conda using the full path, for example, /usr/bin/conda. PATH system variable enable a way to quickly reach commonly-used executables.

To sum it up, conda "command not found" (in Linux and macOS) or "conda not recognized as internal or external command" in Windows simply indicates that the operating system cannot find conda in one of the directories where executables are usually placed.

Add conda to PATH environment variable

The first thing you should do is to add conda to PATH environment variable. Normally this was done automatically by the Anaconda installer or package manager, but you need to be sure the OS knows where to look for conda.

On Linux

On Linux, you can add conda to PATH using export. Open up a terminal and run the following command.

export PATH=/path/to/anaconda3/bin:$PATH
Code language: JavaScript (javascript)

Replace /path/to/anaconda3/bin to where you place anaconda3, usually it was installed in /home/your_username.

The command makes changes to the current session only and will not persistent though restarts.

If you don't want to do this every time you start a session, you can add that command into .bashrc file so that it is starts up with the terminal.

echo 'export PATH=/path/to/anaconda3/bin:$PATH' >> ~/.bashrc
Code language: PHP (php)

On Windows

On Windows, you have to go to Control Panel > System and Security > System > Advanced System Settings, look for System Variables.

image-20210620232257551

Under the System Variables section, find the row named Path and click Edit. You need to add

Screenshot of Edit Environment Variables

You need to add the Anaconda installation folder C:\Users\your_username\Anaconda3\ (replace your_username with your actual account name) to the list of paths.

Use conda init

init is a new command added to Conda v4.6 and later to ensure users have a properly configured terminal set up automatically.

We prefer adding conda to PATH ourselves, but if that doesn't work out for you, maybe you should try running the following command:

Linux/UNIX (OS X < 10.15)

./anaconda3/bin/conda init

Mac OS X >= 10.15

./anaconda3/bin/conda init zsh

Windows

./anaconda3/Scripts/conda.exe init

zsh users

./anaconda3/bin/conda init zsh

The init command supports other shells, too, including bash, cmd.exe, fish, powershell, tcsh, xonsh, zsh.

Once the script is done running, you must launch a new terminal command for the settings to take effect.

If things didn't go well, you can always reverse the changes made by conda init by running

./anaconda3/bin/conda init --reverse

Set up zsh to read .bashrc

If you're just switching to zsh and getting the following error message, you might not set up zsh to read .bashrc.

In any terminal, run nano ~/.zshrc to edit zsh configuration file and add the following line to it.

source ~/.bash_profile
edit .zshrc

Now close your terminal and open it all over again, verify that zsh now loads bash configuration and conda works again.

conda not recognized on Windows

On Windows, you should get 'Conda' is not recognized as internal or external command if the OS does not find it in the PATH.

Recent Windows 10 releases does not assume you have administrator privileges to install or update. You can force administrative re-installation by right-click on the Anaconda Command Prompt, choose "Run as administrator".

Alternatively, you can use Anaconda Navigator or the Anaconda Command Prompt (located in the Start Menu under “Anaconda”) when you wish to use Anaconda software, as per Anaconda recommendation.

image-20210621001117068

conda not found in Git Bash

If you use Git Bash on Windows, it is out of conda init support.

In order to manually configure conda to work with the Git Bash shell, you need to add conda.sh from Anaconda3 installation into .bashrc.

First, open up C:\ProgramData\Anaconda3\etc\profile.d, right-click in any blank space and select Git Bash Here to open up a new Git Bash terminal right where you are now.

image-20210621002332940

After that, copy and paste the following command into the terminal and run it.

echo ". '${PWD}'/conda.sh" >> ~/.bashrc
Code language: PHP (php)

Basically it puts a new line in the current .bashrc configuration file that loads conda.sh every time it starts.

We hope that you've learned how to fix conda "command not found" error and get it to work again. Conda is a great package manager designed specifically for data scientist and the users who are not familiar with Python, pip and pipenv/virtualenv as a whole.

If you want to learn more about Python, check out our other posts about common errors in Python such as "too many values to unpack" or locale.Error: unsupported locale setting.

Click to rate this post!
[Total: 18 Average: 5]

Leave a Comment