Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to install python 2 on OS X?

A colleague of mine wants to use my python 2 code on his OS X (10.6) machine. My code imports several built-in python packages, including Tkinter and shelve, and also uses third-party packages, including numpy, scipy, matplotlib, and ipython.

I've encountered a few problems with OS X's built-in python. (IDLE doesn't work, for example*). I suspect I should install a more recent version of python, and a different version of Tk.

My questions:

  1. Will having two different versions of python/Tk on the same machine cause problems?

  2. I would like to associate the terminal commands 'python', 'ipython', and 'easy_install' with the more recent version of python. How should I do this?

  3. When I install third-party packages like numpy using a .dmg file, how do I control which version of python numpy installs into?

  4. Is there a better way to do this?

If this process goes well, I'd consider adding OS X instructions to my code's documentation, so I'd like to boil down this process to the simplest, most general approach.

*EDIT: Also, this

EDIT: Thank you everyone for the useful answers. My colleague tried MacPorts, which seems to work well, but has a few speedbumps. First we had to install Xcode from the system install disk. This is not a fast or lightweight install (several GB). Luckily we still had the disk! Once Xcode was installed, MacPorts was easy to install. Python and the python subpackages we needed were also easy to install, but he told me this installation took several hours. Presumably this delay is due to compilation? He had an easy time setting the MacPorts python as default. However, I think we have to change the 'Python Launcher' application by hand, this seems to still default to the system python.

Even though he has a working system now, I'm tempted to ask him to try one of the other solutions. I'm not sure all of my code's potential users will tolerate a multi-hour, multi-gigabyte installation.

like image 821
Andrew Avatar asked Nov 29 '22 17:11

Andrew


1 Answers

I use brew to install all my libraries/compilers/interpreters.

To install python try this:

brew install python

Then add Python's binaries directory to your $PATH in your ~/.profile:

export PATH=`brew --prefix python`/bin:$PATH

I'd recommend you to install pip, virtualenv and virtualenvwrapper to have better control over your environment too.

like image 148
igorgue Avatar answered Dec 04 '22 05:12

igorgue