Ubuntu – Command ‘python’ not found after creating conda environment


I am running Ubuntu 19.10 on my laptop, I recently installed miniconda3. No problems this far, but after creating an environment with python 2.7 I get the following message everytime I open a terminal:

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

So I followed the advise and installed python, then this error occured:

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

My guess is that bash is trying to access the conda python 2.7?
Here is what I get by running which python without conda active:

which python


which 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

with conda activated here are the corresponding results:

which python


which 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

This is what conda adds to the .bashrc file:

# >>> 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"
    if [ -f "/home/rustax/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/home/rustax/miniconda3/etc/profile.d/conda.sh"
        export PATH="/home/rustax/miniconda3/bin:$PATH"
unset __conda_setup
# <<< conda initialize <<<

Thank you in advance for any help you can provide

Best Answer

  • Sorry for all the fuss but I have solved the problem. Since Ubuntu 19.10 doesn't come with python2 pre-installed what I did to get rid of the problem was to first remove python (since I installed it after installing conda, note that this is python and not python3 since python3 comes pre-installed) and conda completely with the following lines.

    sudo apt-get purge --auto-remove python
    rm -rf ~/miniconda3
    rm -rf ~/.condarc ~/.conda ~/.continuum

    After this I installed python

    sudo apt install python

    And after installing python I installed conda the normal way and now I don't get any of the error messages posted when I open up a terminal. I guess order of PATH variables matters. Since when I had troubles I first installed conda and followed up by installing python and think that condas python path might have come first.

  • Related Question