After Anaconda installation, conda command fails with "ImportError: no module named conda.cli"

Note

If the accepted answer doesn't work, then this answer might help.

The Cause

According to the official thread on 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.

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.

  • 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
    

Now, your anaconda is up-to-date.


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:

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.

Enjoy!


If anaconda was installed by the root user, a permissions issue could produce the ImportError: No module named 'conda.cli' error.

Something like this

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 create -n [my_conda_root] --clone=[current_conda_dir]

But for this to work, you will need at least the read and traverse permissions.


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).

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

conda install -y python==3.6.9