我在笔记本电脑上运行 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?以下是我在which python
未启用 conda active 的情况下运行时得到的结果:
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
这是 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
抱歉打扰了大家,但我已经解决了这个问题。由于 Ubuntu 19.10 没有预装 python2,我为了解决这个问题所做的是首先删除 python(因为我是在安装 conda 之后安装的,请注意这是 python 而不是 python3,因为 python3 是预装的),然后使用以下几行完全删除 conda。
sudo apt-get purge --auto-remove python
rm -rf ~/miniconda3
rm -rf ~/.condarc ~/.conda ~/.continuum
之后我安装了python
sudo apt install python
安装 python 后,我以正常方式安装了 conda,现在打开终端时没有收到任何错误消息。我猜 PATH 变量的顺序很重要。因为当我遇到麻烦时,我首先安装了 conda,然后安装了 python,我认为 condas python 路径可能先出现。