3

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

proton
  • 147
  • 2 more questions: 1. What is your full $PATH statement? Running echo $PATH will show this. 2. Which guide have you followed to install anaconda? – andrew.46 Sep 23 '16 at 22:56
  • @andrew.46 I edited the post with answers – proton Sep 23 '16 at 23:00
  • Note that your full $PATH does not include a call to anaconda? The correct syntax for ~/.profile should be: export PATH=$PATH:/home/name/anaconda3/bin and I suspect you have made a mistake here. If this does not fix the issue can you pastebin your ~/.bashrcand ~/.profile? – andrew.46 Sep 23 '16 at 23:14
  • @andrew.46 .profile : http://pastebin.com/EZkAnBLY, .bashrc: http://pastebin.com/s3w9LLZ0 – proton Sep 24 '16 at 06:51
  • I see the error, it is as I suspected in your ~/.profile file.Have a look at my answer and I suspect this can all be cleared up :) – andrew.46 Sep 24 '16 at 07:02

3 Answers3

2

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

andrew.46
  • 38,003
  • 27
  • 156
  • 232
  • that is exactly what is said in the link... – proton Sep 23 '16 at 22:38
  • @proton OIC, try running the command source ~/.profile But what is the path to anaconda? Are you writing in literally: /usr/path/to/anaconda3/bin ? the correct path must be added... – andrew.46 Sep 23 '16 at 22:41
  • i tried using source ~/.profile but python stil claims numpy cannot be found. I wrote the correct and same path both in .profile and in export – proton Sep 23 '16 at 22:49
  • it doesnt help. http://pastebin.com/044DSpMQ – proton Sep 24 '16 at 07:12
  • it doesnt help. http://pastebin.com/044DSpMQ calling echo $PATH in the in the window whera 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

    – proton Sep 24 '16 at 07:19
  • ALmost there. The export command should make the path available throughout, but reboot to be sure and cross your fingers as well :) – andrew.46 Sep 24 '16 at 07:23
  • reinsatlling doesn't help since it always skips that line and now it also installed on /root, rebooting doesent help either – proton Sep 24 '16 at 07:33
  • @proton ~/.profile is sourced only by login shells, which is why it's not available in other terminals without sourcing. It should work after logging out and back in but sometimes graphical shells do not seem to source ~/.profile. You could add the export line to your ~/.bashrc and then it will be available in any terminal, if you can't get it working using ~/.profile – Zanna Sep 24 '16 at 07:54
  • after rebooting, I can launch IPython from any window and import whatever I want. but if I just use python3 it does'nt recognise any package. – proton Sep 24 '16 at 07:58
  • @andrew.46 do you know how to choose yes when anaconda ask to change the PATH? it automaticall chosses no – proton Sep 24 '16 at 08:58
  • @proton The default is 'no' so you have to simply type in 'yes'. I have added these details to my very long answer :) – andrew.46 Sep 24 '16 at 09:12
  • but anacodna doesn't wait for me to decide, it just goes on – proton Sep 24 '16 at 09:17
  • since this is another topic. I asked another question http://askubuntu.com/questions/829015/python3-default-intepreter – proton Sep 24 '16 at 10:10
1

I follow those steps and works for me!

Installing Anaconda #

At the time of writing this article, the latest stable version of Anaconda is version 2020.02. Before downloading the installer script, visit the Downloads page and check if there is a new version of Anaconda for Python 3 available for download.

Complete the following steps to install Anaconda on Ubuntu 20.04:

1- Anaconda Navigator is a QT-based GUI. If you are installing Anaconda on a desktop machine and you want to use the GUI application, install the following packages. Otherwise, skip this step.

$sudo apt install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6

2- Download the Anaconda installation script with your web browser or get :

$wget -P /tmp https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh

The download may take some time depending on your connection speed.

3- This step is optional, but it is recommended to verify the data integrity of the script.

Use the sha256sum command to display the script checksum:

$sha256sum /tmp/Anaconda3-2020.02-Linux-x86_64.sh

The output should look like this:

2b9f088b2022edb474915d9f69a803d6449d5fdb4c303041f60ac4aefcc208bb  /tmp/Anaconda3-2020.02-Linux-x86_64.sh

Run the script to start the installation process:

$bash /tmp/Anaconda3-2020.02-Linux-x86_64.sh

You should see an output like the following:

Welcome to Anaconda3 2020.02

In order to continue the installation process, please review the license agreement. Please, press ENTER to continue

Press ENTER to continue. To scroll through the license, use the ENTER key. Once you’re done reviewing the license, you’ll be asked to approve the license terms:

Do you approve the license terms? [yes|no]

Type yes to accept the license, and you’ll be prompted to choose the installation location:

Anaconda3 will now be installed into this location:

/home/linuxize/anaconda3

- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below

The default location should be fine for most users. Press ENTER to confirm the location.

The installation may take some time, and once completed, the script will ask you whether you want to run conda init. Type yes.

Installation finished.

Do you wish the installer to initialize Anaconda3 by running conda init? [yes|no]

This will add the command-line tool conda to your system’s PATH .

To activate the Anaconda installation, you can either close and re-open your shell or load the new PATH environment variable into the current shell session by typing:

$source ~/.bashrc

To verify the installation type conda in your terminal.

That’s it! You have successfully installed Anaconda on your Ubuntu machine, and you can start using it.

Updating Anaconda # Updating the Anaconda is a pretty straight forward process. Open your terminal and enter:

conda update --all

for more information and more clear explanation go to the source link below

Resurse

Kasem777
  • 111
1

Just reinstall again and on the last question "do you want to add the path" answer yes. You must've answered no.

Merry
  • 11