【发布时间】:2020-04-08 06:45:55
【问题描述】:
我在笔记本电脑上运行 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 <<<
提前感谢您提供的任何帮助
【问题讨论】:
-
你说这个错误是在你新建conda环境后发生的。你是如何创建这个环境的?
-
conda create -n myenv python=2 但我查了一下,它不仅是在创建环境之后。更新新的 conda 安装后也会发生这种情况。我使用以下命令进行了更新: conda update --all
-
请编辑您的问题以显示您为创建环境运行的命令、您如何激活环境以及您如何尝试运行 Python。
-
抱歉,我已经解决了这个问题。 :P 很简单的一个 tbh。
标签: python ubuntu anaconda conda miniconda