0

I would like to make the version of python 2 packaged with MacOS the system default Please show me the recommended approach.

I have installed a Python 3 version from miniconda/anaconda, and my current default Python is:

$ which python
/Users/PatrickT/miniconda3/bin/python 

I do not want this to be the default Python anymore. The dilemma is: if I remove conda from the PATH, I can access the Python version packaged with the OS, but then I can no longer access the conda Python...

PatrickT
  • 10,037
  • 9
  • 76
  • 111

2 Answers2

1

It sounds like you might want a python version manager, such as https://github.com/yyuu/pyenv

I can't vouch for this specific tool, but there are several similar utilities for ruby (rbenv, rmv) that are great.

OS X (or is it macOS now?) come with an installed version of Python. You almost certainly don't want to mess with that since updates to the OS will likely overwrite your changes. You may want to consider a tool called homebrew for OS X -- it lets you install specific versions of tools like python and manages them externally to the built-in versions.

Tom Harrison
  • 13,533
  • 3
  • 49
  • 77
  • Thank you Tom. At this time, I'm after setting up the PATH or symlink properly to point to the OS python2. Thanks for pointing the python version manager tool, I'll look it up! – PatrickT Jun 19 '16 at 18:41
  • ``introduced as Mac OS X in 2001, renamed OS X in 2012, and renamed macOS in 2016`` What a mess! I always say osx as it easier for me to remember and more google friendly ;-) – PatrickT Jun 19 '16 at 18:44
  • In the end, the version manager software probably just symlinks (this is what the Linux "alternatives" system does), but if you're really in states where you want one version for one thing, and another, the version manager is probably worth it – Tom Harrison Jun 19 '16 at 18:45
  • I have installed ``pyenv`` (via homebrew), but from a cursory reading it would seem that this version manager will manage only python versions installed via ``$pyenv install``, but I couldn't see how it could help me deal with the original OS version and/or with versions installed via ``pip`` or ``fink`` or some other way, right? – PatrickT Jun 19 '16 at 19:12
  • 1
    That's the way the similar ruby managers work ... except that they put their versions in the path first, so if you need a specific version (even if it's the same as the one installed by masOS) just use pyenv to install another copy. But if this doesn't work, I don't have much more to offer :-) – Tom Harrison Jun 21 '16 at 18:11
0

Edit the .bash_profile

$ nano ~/.bash_profile

1. delete any reference to "export PATH=" to non-default-os python.

2. set up aliases to alternative python versions.

In other words, replace e.g. this:

# added by Miniconda3 4.0.5 installer
export PATH="/Users/PatrickT/miniconda3/bin:$PATH"

with this:

## create alias to miniconda/anaconda
## to make conda command accessible, first run: condainit
alias condainit='export PATH="/Users/PatrickT/miniconda3/bin:$PATH"'

## create alias to other python versions
alias pyconda='/Users/PatrickT/miniconda3/bin/python'
alias python3='/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}'

## After installing pyenv with homebrew and run $ brew info pyenv
## set the following, according to the "caveat instructions":
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

Source the .bash_profile:

$ source ~/.bash_profile

To access conda commands run this in the terminal:

$ condainit
$ conda info -e

To access the Python3 provided by conda, type:

$ pyconda

To access the Python3 installed via the dmg, type:

$ python3

To access the default OS-provided python (currently Python 2.7), type:

$ python

Among other sources, the following was particularly useful: Using two different Python Distributions

Community
  • 1
  • 1
PatrickT
  • 10,037
  • 9
  • 76
  • 111