20

Recently, I installed Anaconda3-2.5.0-Linux-x86_64.sh on my 15.04 and ended up with this!

:~$ python --version
Python 3.5.1 :: Anaconda 2.5.0 (64-bit)

:~$ python2 --version
Python 2.7.9

:~$ python3 --version
Python 3.5.1 :: Anaconda 2.5.0 (64-bit)

During the last moments of installation, I did enter something as yes in hurry, and I suppose it had to do something with this. (Ok, my fault, I should have handled that carefully, but I need help now, not criticism).

Screenshot

AFAIK this is definitely going to break other programs. What do I do now?


What I think could work.

Can this be done using aliases?

alias python=python2

But I ain't sure.

muru
  • 207,228

5 Answers5

18

I went through the installation in a VM, and the following happend.

  1. The installer asks for an install location. Default is /home/myuser/anaconda3.
  2. At the end you'll be asked

    Python 3.5.1 :: Continuum Analytics, Inc.
    creating default environment...
    installation finished.
    Do you wish the installer to prepend the Anaconda3 install location
    to PATH in your /home/myuser/.bashrc ? [yes|no]
    [no] >>> yes
    
    Prepending PATH=/home/myuser/anaconda3/bin to PATH in /home/myuser/.bashrc
    A backup will be made to: /home/myuser/.bashrc-anaconda3.bak
    

To restore the old behavior, go to your home directory and do

mv .bashrc-anaconda3.bak .bashrc

then start a new shell.

As you suggest, you could alias python=python2, but I find that a bit weird. I would

  1. Restore the original .bashrc
  2. Create (if it does not exist) ~/bin
  3. Link ln -s ~/anaconda3/bin/python3 ~/bin/python3
  4. [Prepend $HOME/bin to $PATH](Should already be set by default by ~/.profile)
  5. Relogin.

That way, calling python3 will start the one from Anaconda.


An important point is, that the original /usr/bin/python is still there, and still points to python2.7. The ramifications of having python->python3 in your path depend on how a specific script is called.

If the shebang #!/usr/bin/python is used, like it probably is in all executables that ship with Ubuntu, nothing will change. On the other hand, for better portability #!/usr/bin/env python is sometimes used, which will now cause python3.5 to be called.

Nephente
  • 5,875
7

Good answer here: https://stackoverflow.com/questions/24405561/how-to-install-2-anacondas-python-2-7-and-3-4-on-mac-os-10-9

conda create -n python2 python=2.7 anaconda

then, to switch:

source activate python2
3

In case anyone is looking to change their python default version back to 2.7 after messing it up(by changing default one to: anaconda or python 3) and ending up with non-functional software, just follow this link: Link with instructions to change default python version.

1

This worked for me but for Miniconda, it should also work for Anaconda but please correct me if I'm wrong.

First get your $PATH variable:

echo $PATH

It will probably look like this (miniconda path before everything else):

/home/your_user/miniconda3/bin:$PATH

Copy that path to the bottom of your ~/.bashrc file, but with Miniconda at the end instead of the beginning of the path like so:

export PATH="$PATH:/home/your_user/miniconda3/bin"

The system will look for programs at the start of the $PATH variable before the miniconda3/bin folder.

It should restore the versions for previous programs you had like python.

Starting in Conda 4.4, they changed the code added to ~/.bashrc. Now, to achieve the same thing, edit ~/.bashrc and comment out the line below like so to prevent the base layer (base environment) from activating in every terminal. No need to touch any other part of the new additions. I am uncertain what significance CONDA_CHANGEPS1=false has, but haven't run into any issues so far.

   # CONDA_CHANGEPS1=false conda activate base

And while you won't see the conda folder in the path anymore, the conda command will still run fine, and your original python, python3, and pipenv commands will as well.

pedrodcb
  • 11
  • 4
0

Here is my answer, and it may or may not be the actual specific answer to what you have done to your own system.

However, I am in a similar situation and had the very same concern.

I am using Ubuntu 16.04 LTS and Python 2.7.12, and just recently installed Anaconda.

So now, when I go to the command line and type python it still goes to my Python2 installation.

Confirmed by this sequesnce:

$which python
/usr/bin/python     <  Catch-all for max compatibility
$python
Python 2.7.12 . . etc

So in my case, anaconda does NOT cause any problem with my default Python2 shebangs.

Ultimately, that is the question.

When you ask the system which python you can trust that to be correct string to use in the first line of your command-line style Python programs.

In my situation, all my same Python command-line script files continue to execute just fine.

I tend to write Python in a 3-compatible mode. Such as using parentheses around my print statements. But I am actively resisting a major change to the system that might cause hard-fought Python 2 programs to encounter glitches. Python 3 sounds great but unnecessary for my needs. Python 2 is an amazing language.

My computing environment does not allow me to go back and re-engineer past processes that have been tuned to work correctly without taking a mjor time hit since I would have to go back and figure out where I used it in the first place.


Bottom line for me: Upon install anaconda for future use, I have not had any speed bumps nor problems.


That is the point where I am in the process... Just finished re-certifying all the past software.


Next step is to actually use some of the cool stuff that is promised in the package.


So, I must suspect that other simply installing anaconda there must be more to your situation.

From my experience it is not a problem at all.

SDsolar
  • 3,219