Ubuntu – Installing anaconda

anacondapython

I tried to install anaconda on my Ubuntu VM (following this), but for some reason the installation skipped on adding anaconda to the PATH variable.
I followed instructions here and it somewhat helped. Now I have to call:

export PATH=$PATH:/home/myname/anaconda3/bin

every time. It works (for example, if I want to import numpy) , but obviously not comfortable. how can I solve it so it will work from now?

this is the PATH variable –

PATH="$HOME/bin:$PATH:/home/name/anaconda3/bin"

and echo $PATH returns /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

when I try to import I get –

    >>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'numpy'

right now, calling echo $PATH in the in the window where i called source gives

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ofirarzi/anaconda3/bin:/home/ofirarzi/anaconda3/bin

but in any other window I get

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Best Answer

There are 2 possible solutions:

1. Correct the $PATH statement manually:

You have made an error in your ~/.profile file which accounts for anaconda not being in your $PATH. Your have added here:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH:/home/ofirarzi/anaconda3/bin" <-------
fi

which is incorrect as the conditional statement tests for the directory $HOME/bin and if this is not present the extra $PATH will be ignored. In your case I suspect you do not have a $HOME/bin...

Try the following instead (leaving preceding lines of ~/.profile untouched):

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

export PATH=/home/ofirarzi/anaconda3/bin:$PATH

Note that the new anaconda $PATH is prepended rather than appended as explained in this post. Then test by running the following two commands:

source ~/.profile
echo $PATH

And now all should be well, if not:

2. Allow the installer to correct the $PATH:

If there is still some trouble I note that the anaconda installer offers to make the required changes for you. I installed on Xenial and saw the following offer at the end of installation (the arrows are my addition):

creating default environment...
installation finished.
Do you wish the installer to prepend the Anaconda2 install location
to PATH in your /home/andrew/.bashrc ? [yes|no]    <-----
[no] >>> yes                                       <-----

Prepending PATH=/home/andrew/anaconda2/bin to PATH in /home/andrew/.bashrc
A backup will be made to: /home/andrew/.bashrc-anaconda2.bak


For this change to become active, you have to open a new terminal.

Thank you for installing Anaconda2!

Share your notebooks and packages on Anaconda Cloud!
Sign up for free: https://anaconda.org

andrew@athens:~$ 

And on my Xenial system typing 'yes' added the following to ~/.bashrc:

# added by Anaconda2 4.1.1 installer
export PATH="/home/andrew/anaconda2/bin:$PATH"

So a re-installation of anaconda is another option, allowing the installer to do the hard work :)

Related Question