conda command will prompt error: "Bad Interpreter: No such file or directory"
Solution 1
Something must have gone wrong during the installation, I suppose. The bad interpreter means that a script is looking for an interpreter that doesn't exist - as you rightfully pointed out.
The problem is likely to be in the shebang #!
statement of your conda script.
From Wikipedia: Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script.
If you run
cat ~/anaconda3/bin/conda
You will probably get the following:
#!/opt/anaconda1anaconda2anaconda3/bin/python
if __name__ == '__main__':
import sys
import conda.cli
sys.exit(conda.cli.main())
Changing the first line to point a correct interpreter, i.e., changing it to:
#!/home/lukasz/anaconda3/bin/python
Should make the conda
command work.
If you are sure that you installed everything properly, then I'd suggest maybe reaching out for support from the anaconda community.
Solution 2
I encountered the same error while trying
conda
The error you should interpret as follows:
bash: "path_to_file_with_error": "path_to_file_it_points_to":
bad interpreter: No such file or directory
How to fix Type in terminal
nano "path_to_file_with_error"
Change first line of the file to correct path of the python (in my case it was in miniconda/bin)
Solution 3
As the response above, this issue can be solved by changing the
#!/opt/anaconda1anaconda2anaconda3/bin/python
to
#!/opt/anaconda3/bin/python
However, as soon as you do the next installation, e.g. "conda install [...]" this will be changed again to anaconda1anaconda2anaconda3, for whatever reasons.
You might also realize some installation warnings and errors which are very likely to be related to this problem. If you want to get rid of this problem, you have to solve this warnings and errors. My strongest assumption is that there are missing administrator rights causing this problem, when you attempt to installs some conda packages the first time.
Solution 4
When you change the path to the interpreter conda will not be activated, so by following any of the previous answers you will end up in dead end.
you get the following
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
So to solve this renaming path issue you need to: you can use any text editor:
nano ~/anaconda3/etc/profile.d/conda.sh
change the CONDA_EXE and CONDA_PYTHON_EXE paths to the correct path example:
export
CONDA_EXE='/home/yourusername/anaconda3/bin/conda'
export _CE_M=''
export _CE_CONDA=''
export CONDA_PYTHON_EXE='/home/yourusername/anaconda3/bin/python'
then last step do:
source ~/anaconda3/etc/profile.d/conda.sh
To test your conda
Try:
conda activate
conda deactivate
to make this change permanent to all terminals please add this line to ~/.bashrc
source ~/anaconda3/etc/profile.d/conda.sh
Solution 5
If somebody runs into this problem and none of the above solutions works, it could be that on some update process the conda executable (which is a python script) was replaced with an identical-looking script with one key difference, it contains windows line endings. This results in that executing the script via bash e.g.:
<some_path>/conda/bin/conda
will result in the error, but executing directly via python works
<some_path>/conda/bin/python <some_path>/conda/bin/conda
Can be fixed by dos2unix
dos2unix <some_path>/conda/bin/conda
or just move the file away and move it back.
Lukasz
Updated on February 08, 2022Comments
-
Lukasz about 2 years
I'm using arch linux and I've installed Anaconda as per the instruction on the Anaconda site. When I'm attempting to run
conda info --envs
I get the following error:bash: /home/lukasz/anaconda3/bin/conda: /opt/anaconda1anaconda2anaconda3/bin/python: bad interpreter: No such file or directory
I've tried looking for the directory
/opt/anaconda1anaconda2anaconda3/bin/python:
but it simply doesn't exist.Furthermore, when I run python from the terminal it runs as normal with the following displayed at the top
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information.
for completeness my
.bashrc
file resembles:# # ~/.bashrc # # If not running interactively, don't do anything [[ $- != *i* ]] && return alias ls='ls --color=auto' PS1='[\u@\h \W]\$ ' # added by Anaconda3 4.0.0 installer export PATH="/home/lukasz/anaconda3/bin:$PATH" # python startup for up keys export PYTHONSTARTUP=$HOME/.pythonstartup
I've tried following this and making the the appropriate changes but nothing, I've also attempted to do this but there really isn't a solution posted.
I would like to try to fix this without having to remove Anaconda and reinstalling it.
-
Lukasz over 7 yearsThat's the exact output I get when I run
cat ~/anaconda3/bin/conda
. I'm trying to change the first line to point to a correct interpreter but I'm unsure how to accomplish that. -
Morteza Mashayekhi about 7 yearsThis solution is applicable to ipython as well, which needs to do the same thing with cat ~/anaconda3/bin/ipython. The problem happened to me when I moved my python folder to somewhere else.
-
Hesham Eraqi almost 5 yearsThis a very neat solution. Thanks.
-
Charlie Parker over 4 yearsis the anaconda community link still working for you?
-
Mwibutsa Floribert almost 4 yearsIt should point to the anaconda installation path, and that would be the case if you have yours in the /opt/ directory
-
Thinkeye about 3 yearsNo, the support link is dead and it's not obvious where it should go now. I would say maybe: docs.anaconda.com/anacondaorg. BTW: I have just used
cd /
andsudo ln -s /home/user/anaconda3
to join the assumed and real location of the directory. -
dangom about 3 yearsThx for the comments. I've fixed the dead link to have it point to the new location.