创建conda环境后找不到命令“ python”

时间:2019-12-15 16:34:43

标签: python ubuntu anaconda conda miniconda

我在笔记本电脑上运行Ubuntu 19.10,最近安装了miniconda3。到目前为止没有问题,但是在使用python 2.7创建环境之后,每次打开终端时都会收到以下消息:

Command 'python' not found, but can be installed with:
sudo apt install python3         # version 3.7.5-1, or
sudo apt install python          # version 2.7.17-1
sudo apt install python-minimal  # version 2.7.17-1

所以我按照建议安装了python,然后发生了此错误:

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
ImportError: No module named conda

我的猜测是bash试图访问conda python 2.7? 这是我在没有激活conda的情况下运行which python的结果:

which python

/usr/bin/python

which python3

/usr/bin/python3

whereis python

python: /usr/bin/python2.7 /usr/bin/python3.7 /usr/bin/python3.7m /usr/bin/python /usr/lib/python3.8 /usr/lib/python2.7 /usr/lib/python3.7 /etc/python2.7 /etc/python3.7 /etc/python /usr/local/lib/python2.7 /usr/local/lib/python3.7 /usr/include/python3.7m /usr/share/python /usr/share/man/man1/python.1.gz

在激活conda的情况下,是相应的结果:

which python

/home/rustax/miniconda3/bin/python

which python3

/home/rustax/miniconda3/bin/python3

whereis python

python: /usr/bin/python2.7 /usr/bin/python3.7 /usr/bin/python3.7m /usr/bin/python /usr/lib/python3.8 /usr/lib/python2.7 /usr/lib/python3.7 /etc/python2.7 /etc/python3.7 /etc/python /usr/local/lib/python2.7 /usr/local/lib/python3.7 /usr/include/python3.7m /usr/share/python /home/rustax/miniconda3/bin/python3.7-config /home/rustax/miniconda3/bin/python3.7m /home/rustax/miniconda3/bin/python3.7 /home/rustax/miniconda3/bin/python3.7m-config /home/rustax/miniconda3/bin/python /usr/share/man/man1/python.1.gz

我尝试创建从/ home / rustax / miniconda3 / bin / python到/ usr / bin / python的符号链接,但出现了相同的错误。

Conda将以下行添加到.bashrc:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/rustax/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/rustax/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/home/rustax/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/rustax/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

在此先感谢您提供的帮助

1 个答案:

答案 0 :(得分:0)

很抱歉,但是我已经解决了这个问题。由于Ubuntu 19.10并未预装python2,我要解决的问题是首先删除python(因为我在安装conda之后安装了它,请注意,这是python而不是python3,因为python3已预先安装)和conda完全按照以下几行进行。

Failed to execute goal com.googlecode.maven-download-plugin:download-maven-plugin:1.3.0:wget (default-cli) on project ProjectName: The parameters 'url' for goal com.googlecode.maven-download-plugin:download-maven-plugin:1.3.0:wget are missing or invalid

此后,我安装了python

sudo apt-get purge --auto-remove python

rm -rf ~/miniconda3

rm -rf ~/.condarc ~/.conda ~/.continuum

在安装python之后,我以正常方式安装了conda,现在打开终端时我没有收到任何错误消息。我猜想PATH变量的顺序很重要。自从遇到麻烦以来,我首先安装了conda,随后安装了python,并认为condas python路径可能首先出现。