When people talk about Python’s benefits the discussions typically center around the language’s syntax and overall design. And to be sure, those points are a large part of why Python’s such a beloved programming language. But the tools used with the language are also part of its success. And package managers like Pip and Conda are among the most important tools. But correct usage of these tools isn’t always self-apparent. For example, what exactly does a “conda command not found” error mean? Thankfully the solution is usually fairly straightforward.
What Does the Error Mean?
One of the reasons why this error can be so hard to solve is that the message is a little misleading. The error’s wording implies that Conda is erroring out due to a missing command. But what’s actually happening is that the operating system’s command line shell is trying to run the “Conda” command and isn’t finding an associated binary in its path. In short, it’s an operating system error and not strictly a Python error. However, the cause of the error often overlaps with your Python installation. But understanding the problem requires a deeper dive into Conda, Anaconda, and package management.
An Overview of Conda
Conda is a relatively advanced tool that can be used for a wide variety of different tasks. However, in Conda’s most basic state, it can be thought of as analogous to Pip. Both of these tools are package managers. Package in this case refers to a collection of code and the various items needed to make it run.
For example, consider a case where you want to use a hypothetical web scraper called ComplexWebScraper. You might assume it’d be as easy as just adding an “import ComplexWebScraper” into your Python code. But the problem comes in when ComplexWebScraper itself needs to import another library. And that new library might itself need to do the same. And not only do you need to find the right library, but you also need to ensure that the version you install matches up with the ComplexWebScraper requirements.
A package manager simplifies this process by either bundling resources together or noting all requirements and how to automatically resolve them. In this case, you would simply tell Pip or Conda that you wanted to install ComplexWebScraper. Both would note ComplexWebScraper’s requirements and install them for you.
Pip is easily the best-known package manager for Python. In fact, many Python distributions ship Pip alongside the Python interpreter. But Pip isn’t perfect. One of Pip’s biggest limitations is that it only handles Python libraries and not binaries. This tends to not be a big issue for Python developers. After all, you’re probably using Python’s libraries for your projects. But one of the language’s big benefits stems from the fact that it easily integrates with pre-compiled binaries. For example, you might have a DLL written in C++ in order to get the best possible speed. But that’s a binary, not a library in Python’s plain-text format. Conda was written to handle those and similar situations. It can handle just about any type of dependency thanks to the needs of its creators.
Anaconda, which created Conda, typically works within data science. This means that the speed benefits of a compiled binary are often quite beneficial for them even if Python’s standard functionality is enough for most programmers. This is one of the reasons why Pip is a default option and Conda isn’t. Pip is the best and simplest tool for package management that would fit the needs of most users. But most doesn’t mean all. And Conda can be a supremely useful tool. And if you’re seeing the “conda command not found” error you’re probably someone who wants to take advantage of the tool’s benefits. So what exactly is going on with the error and how can you fix it?
Fixing the Conda Error
We noted earlier that the “conda command not found” wasn’t really a Python error but was related to it. This is because the issue with Conda is quite similar to something often seen with Python. The problem comes down to path variables.
When you see “conda command not found” it’s usually in a Linux or other Unix-based environment. And this is typically paired with the use of bash as your shell. Bash generally does a fantastic job as a Unix shell. But it, like any other shell, needs to keep track of where all your files are stored. And this is particularly important for binary files. Try typing the following in bash.
The echo command tells bash to print a string to the screen. In this case, it’s the content of the $PATH variable. Path is set every time you open a bash session so there’s no need to manually do so. When you type this command it should list out a series of directories. These directories usually include folders where your operating system stores executable binaries. Examples include /usr/bin, /usr/local/bin, and /snap/bin.
When you install Conda, typically through the Anaconda installer, it should ask if you want to modify your path. The “conda command not found” error message typically shows up if you pressed n instead of y at that step. You might also have it occur if you installed Conda as root. If you did so the root user’s path would be modified instead of any of the standard user accounts.
Thankfully the error is extremely easy to fix. You simply need to load up the .bashrc of your account in a text editor and export the new Anaconda directory’s path so that Conda is detected. When you installed Anaconda it should have asked for an install location. This is in your home directory by default.
So, with a user name of bob, your install directory would probably be /home/bob/anaconda3. Making the change is quite simple. If you’re using vim as your text editor you could type
Of course you’ll want to change “bob” to whatever your account’s username is. Then you’d add the install directory to .bashrc by putting the following line at the end of .bashrc.
Once you open a new instance of bash it should use the new value. And you can see that in effect by using the echo command to show your $PATH variable. Likewise, once you type conda it should actually launch the tool since bash will look within anaconda’s bin directory for the conda binary.