Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anaconda/MacOS: Change default python version

I was using python with anaconda on osx 10.8 when spyder crashed. When I tried to restart it, the launcher showed it as uninstalled. I figured there might be something wrong with anaconda, so I restarted my computer, but the problem persisted.

Looking into it, I noticed the default version of python had been changed:

$ python --version
Python 3.4.1 :: Continuum Analytics, Inc.

I tried changing it back by using Apple's defaults write, relinking python with ln -sf, simply setting an alias python=python2.7, to no effect.

Then I tried removing python3 with conda, but conda remove python3 won't do the trick. Searching for packages produces this:

$ conda search python
Fetching package metadata: ..
(...)
python                       1.0.1                         0  defaults        
                             (...)
                          .  2.7.5                         2  defaults        
                          .  2.7.5                         3  defaults        
                             (...)
                          *  3.4.1                         0  defaults        

I also looked up Continuum docs, and they recommend leaving 2.7 as standard and using an Anaconda environment if I want to use a different version, which doesn't help me.

Does anybody have any idea of how to change default version back to 2.7?

(Specs are: anaconda 1.7.0, osx 10.8.5, conda 3.5.2)

like image 237
kadu Avatar asked May 29 '14 07:05

kadu


1 Answers

Alright, I found a similar problem in the Continuum mailing list.

This was solved by re-installing python through conda

$ conda install python=2.7
Fetching package metadata: ..
Solving package specifications: .
Package plan for installation in environment /Users/kadu/anaconda:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    conda-3.5.2                |           py27_0         135 KB
    pycosat-0.6.1              |           py27_0          57 KB
    python-2.7.6               |                2        16.5 MB
    pyyaml-3.11                |           py27_0         149 KB
    requests-2.3.0             |           py27_0         564 KB
    ------------------------------------------------------------
                                           Total:        17.4 MB

The following packages will be UN-linked:

    package                    |            build
    ---------------------------|-----------------
    conda-3.5.2                |           py34_0
    pycosat-0.6.1              |           py34_0
    python-3.4.1               |                0
    pyyaml-3.11                |           py34_0
    requests-2.3.0             |           py34_0

The following packages will be linked:

    package                    |            build
    ---------------------------|-----------------
    conda-3.5.2                |           py27_0   hard-link
    pycosat-0.6.1              |           py27_0   hard-link
    python-2.7.6               |                2   hard-link
    pyyaml-3.11                |           py27_0   hard-link
    requests-2.3.0             |           py27_0   hard-link

Proceed ([y]/n)? 

This can also be used to change which is the default package under anaconda environments:

$ conda install python=3.4
Fetching package metadata: ..
Solving package specifications: .
Package plan for installation in environment /Users/kadu/anaconda:

The following packages will be UN-linked:

    package                    |            build
    ---------------------------|-----------------
    conda-3.5.2                |           py27_0
    pycosat-0.6.1              |           py27_0
    python-2.7.6               |                2
    pyyaml-3.11                |           py27_0
    requests-2.3.0             |           py27_0

The following packages will be linked:

    package                    |            build
    ---------------------------|-----------------
    conda-3.5.2                |           py34_0   hard-link
    pycosat-0.6.1              |           py34_0   hard-link
    python-3.4.1               |                0   hard-link
    pyyaml-3.11                |           py34_0   hard-link
    requests-2.3.0             |           py34_0   hard-link

Proceed ([y]/n)? 

However, this would require manually changing the builds to any other packages you use. I had to reinstall spyder, which seems to have caused the bug in the first place and was presumably reinstalled when I tried to launch it under the wrong version. All the other libraries, which I didn't try to reinstall, are still working fine under 2.7.

like image 169
kadu Avatar answered Nov 07 '22 04:11

kadu