18

I want Python 3 (and I do not want to mess with OS X provided python). According to:

https://docs.python.org/3/using/mac.html

I can get Python 3 and live long and prosper, BUT it is not clear what happens when I want to upgrade using the next DMG. As an example I can tell you what happens with R on OS X: you get a GUI in /Application and stuff in /Library/Frameworks. On upgrade the GUI is upgraded and the new framework is placed in the /Library/Frameworks directory, side by side with the old (there is a nice ‘current’ symlink that makes sure that the old stuff is ignored). I always delete the old stuff to avoid accumulating crud, and that’s it. Would this approach work for Phyton?

34

I personally use Homebrew, which is a very nice package manager. If you want to give this a try, first of all make sure you have the XCode Command Line Tools installed on your Mac. Then install Homebrew by typing

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

in the Terminal. Homebrew will place its "Cellar" (the set of all the packages you installed with Homebrew) in /usr/local/Cellar.

Now, about Python 3, once Homebrew is installed simply type

brew install python3

and there we go. You have Python3 installed on your Mac.

Notes:

  • this version will automatically take place instead of the OS X version (if it doesn't, just run brew link python3 - this will symlink python3 into /usr/local/bin/)
  • to update python run brew update in the Terminal (this will update Homebrew) and then brew upgrade python3 if a new version of python3 is found by the command brew update
  • at the end you can run brew cleanup python3 to remove every old version
  • with this fancy package manager, you can also take care of R
  • 1
    Quote: "this version will automatically take place instead of the OS X version (if it doesn't, just run "brew link python3" - this will symlink python3 into /usr/local/bin/)". That is exactly what I do NOT want. I use Homebrew for other stuff and I am not sure I want to go down the Homebrew way... – user1256923 Aug 23 '15 at 17:06
  • Maybe I wasn't that clear. The OS X version still will be available, but the default compiler will be set as the Homebrew-one. If that's what you still do not want, then I don't get it. Just like the R example you provided, it will also create some GUI and the proper Framework will be updated as well. Apologies. – AlessioX Aug 23 '15 at 17:15
  • 3
    The last thing I can say is, considering that HB will symlink things into "/usr/local/bin" and the original Apple stuffs are in "/usr/bin", you can set and edit priority by editing your $PATH environment: if you put "/usr/local/bin" first you'll have the HB version, if you put "/usr/bin" first, you'll have the Apple version. Rather annoying I know, but that's the only option that came to mind – AlessioX Aug 23 '15 at 20:32
  • 2
    You may also use brew unlink python3 to remove the symbolic link. You will now use the osx version when running python. To use the brew version, you can still run, for example, /usr/local/Cellar/python3/3.3.2/bin/python3 or create a symlink like ln -s /usr/local/Cellar/python3/3.3.2/bin/python3 /usr/local/bin/python-3.3.2 and after that, run python-3.3.2. You can also install old version of python3 formulas with HB, and use all of them separately. Check this on how to do that. – madmax1 Aug 23 '15 at 20:39
  • 2
    You don't need to link python3, it will automatically be available as /usr/local/bin/python3. And since OS X doesn't ship with Python 3 anyway, you don't overwrite any preinstalled Python. – skrause Aug 25 '15 at 22:19
14

Use Homebrew :)

brew install python3

To update it:

brew update
brew upgrade python3
  • However does this leave old versions around and which directories does it update? – Mark Aug 23 '15 at 16:02
  • As explained in the link I provided, Hombrew installs everything into /usr/local/Cellar and creates symbolic links for applications in /usr/local/bin. It will not touch anything else in the system. It comes with the brew cleanup command, which removes unused or outdated applications automatically. – madmax1 Aug 23 '15 at 16:29
  • How does it deal with multiple python versions which is what the OP asks and you don't answer – Mark Aug 23 '15 at 16:39
  • It will automatically link to the newest version after an upgrade and brew clean removes any remains of the previous version. – madmax1 Aug 23 '15 at 16:51
0

You can use the Anaconda distribution. Its a free version of Python 3 (and Python2). The Andaconda package will also let you update different python versions and upon installation it sets the proper python path. Anaconda comes with Anaconda Navigator which helps you load python packages and comes also with Spyder 3. A Python IDE type of app.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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