Linux 安装 Anaconda 后,conda 命令失败并显示“ImportError: no module named conda.cli”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19825250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
After Anaconda installation, conda command fails with "ImportError: no module named conda.cli"
提问by pk45059
I installed 64 bit Linux version of Anaconda recently (1.8.0-Linux-x86_64). The installation seemed to work fine:
我最近安装了 64 位 Linux 版本的 Anaconda (1.8.0-Linux-x86_64)。安装似乎工作正常:
$ python
Python 2.7.5 |Continuum Analytics, Inc.| (default, Nov 4 2013, 15:30:26)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
##No issues here
However if I try any of the conda commands, I get an error:
但是,如果我尝试任何 conda 命令,则会收到错误消息:
$ conda info
Traceback (most recent call last):
File "~/anaconda/bin/conda", line 3, in <module>
from conda.cli import main
ImportError: No module named conda.cli
Installation is under my user directory (~/anaconda). I have verified that $PATH contains ~/anaconda/bin. $PYTHONPATH is also set to ~/anaconda/lib.
安装在我的用户目录 (~/anaconda) 下。我已经验证 $PATH 包含 ~/anaconda/bin。$PYTHONPATH 也设置为 ~/anaconda/lib。
Any thoughts on what is wrong with the 'conda' command? My searches do not appear to show any one else reporting this error.
关于“conda”命令有什么问题的任何想法?我的搜索似乎没有显示任何其他人报告此错误。
采纳答案by RubyGladiator
When you were installing it, you missed a section. When conda asked you if it can set your .bashrc file, you probably clicked NO. It's a simple fix: fire up your interpreter and add this line:
当您安装它时,您错过了一个部分。当 conda 询问您是否可以设置 .bashrc 文件时,您可能单击了“否”。这是一个简单的修复:启动您的解释器并添加以下行:
export PATH=/home/add your username here/anaconda/bin:$PATH
export PATH=/home/add your username here/anaconda/bin:$PATH
Now type python
into the interpreter and you will see Anaconda 1.8.0 or whatever version you have. You will have to do this each time you start a new interpreter.
现在输入python
解释器,您将看到 Anaconda 1.8.0 或您拥有的任何版本。每次开始新的口译员时都必须这样做。
Enjoy!
享受!
回答by Dmitri
If anaconda was installed by the root user, a permissions issue could produce the ImportError: No module named 'conda.cli'
error.
如果 anaconda 是由 root 用户安装的,权限问题可能会产生ImportError: No module named 'conda.cli'
错误。
Something like this
像这样的东西
sudo chown -R [username] [anaconda_dir]
sudo chown -R [username] [anaconda_dir]
would help in that case.
在这种情况下会有所帮助。
Alternatively, the conda install could be cloned to another location, such as the user's home directory:
或者,可以将 conda 安装克隆到另一个位置,例如用户的主目录:
conda create -n [my_conda_root] --clone=[current_conda_dir]
conda create -n [my_conda_root] --clone=[current_conda_dir]
But for this to work, you will need at least the read and traverse permissions.
但是要使其工作,您至少需要读取和遍历权限。
回答by Anwarvic
Note
笔记
If the accepted answer doesn't work, then this answer might help.
如果接受的答案不起作用,那么这个答案可能会有所帮助。
The Cause
原因
According to the official threadon GitHub, this problem happens when there is a change in the python version. In my case, the original anaconda installation is anaconda 3 with python3.6
. And I installed a new package which updated python topython3.7
along with some other packages. And this corrupts the anaconda base environment.
根据GitHub上的官方帖子,当python版本发生变化时会发生此问题。就我而言,原始的 anaconda 安装是带有python3.6
. 我安装了一个新包,它更新了 pythonpython3.7
和其他一些包。这会破坏 anaconda 基础环境。
The solution
解决方案
The solution that works for me is pretty simple... reinstall anaconda. I don't know if this is the optimal solution, but this what works for me.
对我有用的解决方案非常简单......重新安装anaconda。我不知道这是否是最佳解决方案,但这对我有用。
- First we need to delete the old installation:
rm -rf ~/anaconda3 rm -rf ~/.condarc ~/.conda ~/.continuum
Then, reinstall Anaconda.
Finally, update all packages (including conda itself) using:
conda update --all
- 首先我们需要删除旧的安装:
rm -rf ~/anaconda3 rm -rf ~/.condarc ~/.conda ~/.continuum
然后,重新安装 Anaconda。
最后,使用以下命令更新所有软件包(包括 conda 本身):
conda update --all
Now, your anaconda is up-to-date.
现在,您的 anaconda 是最新的。
回答by Oliver Zendel
I ran into this problem while downgrading python in a Miniconda3 env. in my Dockerimage. With the Miniconda3-4.5.11-Linux-x86_64.sh installer the initial base python version is 3.7.0; I wanted to downgrade to 3.6.9 and got the "ImportError: no module named conda.cli" error (all in the same layer to reduce the image's size).
我在 Miniconda3 环境中降级 python 时遇到了这个问题。在我的 Dockerimage 中。使用 Miniconda3-4.5.11-Linux-x86_64.sh 安装程序,初始基本 Python 版本为 3.7.0;我想降级到 3.6.9 并得到“ImportError: no module named conda.cli”错误(都在同一层中以减小图像的大小)。
I fix this by using the Miniconda3-4.5.4-Linux-x86_64.sh installer instead (which will give you python==3.6.5) and called
我通过使用 Miniconda3-4.5.4-Linux-x86_64.sh 安装程序来解决这个问题(它会给你 python==3.6.5)并调用
conda install -y python==3.6.9
回答by indrak
I am using Anaconda and I found this Solution from somewhere:
我正在使用 Anaconda,我从某个地方找到了这个解决方案:
Change the content of: /opt/cloudera/parcels/Anaconda-5.2.0/bin/conda
更改内容:/opt/cloudera/parcels/Anaconda-5.2.0/bin/conda
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
from conda.cli import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
to
到
#!/opt/cloudera/parcels/Anaconda/bin/python
# -*- coding: utf-8 -*-
import sys
# Before any more imports, leave cwd out of sys.path for internal 'conda shell.*' commands.
# see https://github.com/conda/conda/issues/6549
if len(sys.argv) > 1 and sys.argv[1].startswith('shell.') and sys.path and sys.path[0] == '':
# The standard first entry in sys.path is an empty string,
# and os.path.abspath('') expands to os.getcwd().
del sys.path[0]
if __name__ == '__main__':
from conda.cli import main
sys.exit(main())