conda command will prompt error: "Bad Interpreter: No such file or directory"

conda command will prompt error: "Bad Interpreter: No such file or directory"

我正在使用 arch linux 并且我已经按照 Anaconda 站点上的说明安装了 Anaconda。当我尝试 运行 conda info --envs 时,出现以下错误:

bash: /home/lukasz/anaconda3/bin/conda: /opt/anaconda1anaconda2anaconda3/bin/python: bad interpreter: No such file or directory

我试过寻找目录 /opt/anaconda1anaconda2anaconda3/bin/python: 但它根本不存在。

此外,当我从终端 运行 python 时,它 运行 正常,顶部显示以下内容

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.

为了完整起见,我的 .bashrc 文件类似于:

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

我试过 and making the the appropriate changes but nothing, I've also attempted to do this但确实没有发布解决方案。

我想尝试修复此问题,而不必删除并重新安装 Anaconda。

我想一定是安装过程中出了什么问题。 错误的解释器意味着脚本正在寻找不存在的解释器 - 正如您正确指出的那样。

问题很可能出在您的 conda 脚本的 shebang #! 语句中。

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.

如果你运行

cat ~/anaconda3/bin/conda

您可能会得到以下信息:

#!/opt/anaconda1anaconda2anaconda3/bin/python
if __name__ == '__main__':
    import sys
    import conda.cli

    sys.exit(conda.cli.main())

更改第一行以指向正确的解释器,即将其更改为:

#!/home/lukasz/anaconda3/bin/python

应该使 conda 命令起作用。

如果您确定已正确安装所有内容,那么我建议您联系 support from the anaconda community.

按照上面的回复,这个问题可以通过更改

来解决
#!/opt/anaconda1anaconda2anaconda3/bin/python

#!/opt/anaconda3/bin/python

但是,一旦您进行下一次安装,例如"conda install [...]" 这将再次更改为 anaconda1anaconda2anaconda3,无论出于何种原因。

您可能还会发现一些很可能与此问题相关的安装警告和错误。如果你想摆脱这个问题,你必须解决这个警告和错误。我最强烈的假设是,当您第一次尝试安装某些 conda 软件包时,缺少管理员权限会导致此问题。

我在尝试时遇到了同样的错误

conda

错误解释如下:

bash: "path_to_file_with_error": "path_to_file_it_points_to": 
bad interpreter: No such file or directory

如何修复 输入终端

nano "path_to_file_with_error"

更改文件的第一行以更正 python 的路径(在我的例子中是 miniconda/bin)

当您更改解释器的路径时,conda 将不会被激活,因此如果按照之前的任何答案进行操作,您将陷入死胡同。

你得到以下内容

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.

因此,要解决此重命名路径问题,您需要: 您可以使用任何文本编辑器:

nano ~/anaconda3/etc/profile.d/conda.sh

将 CONDA_EXE 和 CONDA_PYTHON_EXE 路径更改为正确的路径 示例:

      export 
      CONDA_EXE='/home/yourusername/anaconda3/bin/conda'
      export _CE_M=''
      export _CE_CONDA=''
      export CONDA_PYTHON_EXE='/home/yourusername/anaconda3/bin/python'

最后一步:

source ~/anaconda3/etc/profile.d/conda.sh

测试你的 conda

尝试:

conda activate 
conda deactivate

使此更改永久适用于所有终端 请将此行添加到 ~/.bashrc

source ~/anaconda3/etc/profile.d/conda.sh

对于 centos/Rocky Linux 8 OS: conda 是 32 位应用程序,但 centos OS 是 64 位, 您需要安装以下软件包: yum install glibc.i686

参考: https://forums.centos.org/viewtopic.php?t=14169

如果有人遇到这个问题并且 none 上述解决方案有效,则可能是在某些更新过程中,conda 可执行文件(这是一个 python 脚本)被替换为相同的-looking 脚本有一个关键区别,它包含 windows 行结尾。 这导致通过 bash 执行脚本,例如:

<some_path>/conda/bin/conda

会导致错误,但是直接通过python执行就可以了

<some_path>/conda/bin/python <some_path>/conda/bin/conda

可以通过dos2unix

修复
dos2unix <some_path>/conda/bin/conda

或者将文件移开再移回。