19

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.

  • Yes. use alias python=python2 – Mostafa Ahangarha Mar 20 '16 at 9:41
  • AFAIK this is definitely going to break other programs. What makes you think so? If Anaconda sets Python 3 as the default, it's probably for a reason. – fkraiem Mar 20 '16 at 10:02
  • I already have ruined one of my projects that was written for 2.x, and converting default to 3.x is not encouraged especially since many packages work on 2.x! – sinister Mar 20 '16 at 10:10
  • This is when you are very glad that you took the professional approach and had a clone of your pre-install boot drive to prevent this from becoming a big time-waster. Please see my answer below. I think your install method caused the glitch. So if this happened to me I would revert and retry. Total time would be less than a day to figure out whether it is viable. In my case, as you can see, I am at the end of verifications so can now progress to see if this is worth the effort in the first place. Took a couple days to make sure it hadn't caused a problem, and research work is on track. – SDsolar Dec 19 '17 at 9:44
  • as for specifying the version of Python, be sure you know exactly the ripple effect this can have throughout your whole system. Unless you are just playing, it will really require a full verification process if you change the targets of the default which python shebang results. It takes just a bit of time up front to prevent later discovering that you have painted yourself into the corner of needing to rewrite some of your utilities. Best is to leave things working with the defaults unless you have a lot of time on your hands. – SDsolar Dec 19 '17 at 9:47
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.

| improve this answer | |
  • 3
    "4. Prepend $HOME/bin to $PATH" .. already done by default ~/.profile - just a relogin is needed after creating ~/bin. – muru Mar 20 '16 at 11:15
  • @muru That's true, thanks. Added to the answer. – Nephente Mar 20 '16 at 11:28
  • okay, that worked, thanks! Just to put this into notice, that I had python 3.4.3 also installed previously (and pip and pip3 were both associated with it), now I have 2.7, 3.4, 3.5. Now I'm gonna re-install pip to point it to 3.5! – sinister Mar 20 '16 at 12:17
  • Anaconda comes with its own package manager called conda. It also manages virtual environments. I use that to install packages instead of pip. – Nephente Mar 20 '16 at 12:36
  • 1
    See stackoverflow.com/questions/20994716/… – Nephente Mar 20 '16 at 12:38
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
| improve this answer | |
  • If you need this you could very well have much deeper problems. If your system is important, do a full verification of any Python-dependent commands and/or utilities. Fair warning. – SDsolar Dec 19 '17 at 9:55
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.

| improve this answer | |
  • If a system change goes awry, be sure you can roll it back. Make sure you have good system image backups so any major changes can be reversed quickly if they don't go as you plan. Think professional. If you use amateur techniques then you can't expect professional results. – SDsolar Dec 19 '17 at 9:28
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.

| improve this answer | |
  • Upvote because I think you are correct. This is good to have in the database. However, can I please ask that you be a tad more specific as to version numbers of the software involved? – SDsolar Dec 19 '17 at 8:23
  • Thank you, and I don't really think that the program version matters, this should always work. At the time my installer was at the following version however: Miniconda3 4.3.14. Does that help? – pedrodcb Jan 12 '18 at 22:03
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.

| improve this answer | |
  • FYI, I have a complete Scientific workstation, working on solar dynamics. Also about ephemerals and satellite interactions. It MUST work. SO I am not just a one-trick-pony in all this. I install one thing at a time, and then verify that everything before that works. Then I move on to the next. SciPy, Matplotlab, etc. (My preference for plotting is gnuplot). So please understand that I am submitting this answer as a datapoint from a live 24x7 working system in an academic research environment. This is not a test environment - it is daily production. – SDsolar Dec 19 '17 at 8:05
  • Also, as I alluded to in a comment above, THINK PROFESSIONAL. These systems are in use by very high-level researchers all over the world. -->Make sure your boot drive has a clone before you make any major system upgrades. The dd command is quick and easy, and SATA connections are easy. There is no reason to avoid protecting your system. Just be careful that at each step you can revert any and all changes that might happen. Hard rives are a lot less expensive than your time. (unless you don't think that's true). Grant funds plus a time crunch should be enough incentive. – SDsolar Dec 19 '17 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.