MacOS – ipython/python broken after upgrading to OS X Mavericks

macospython

After upgrading to OS X Mavericks, it seems Python broke. I get the following when I try to run ipython:

~ $ ipython 
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/ipython", line 5, in <module>
    from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

Similarly I noticed that some other packages seem to be missing, even when using the default python (as opposed to ipython):

~ $ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy

numpy definitely worked before the upgrade. Any ideas on what could be causing this?

Update: Just noticed that running sudo easy_install numpy makes numpy work again. It gives the following output:

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
Searching for numpy
Best match: numpy 1.6.2
Adding numpy 1.6.2 to easy-install.pth file

Using /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Processing dependencies for numpy
Finished processing dependencies for numpy

I am 100% sure I had numpy installed already when the machine was still running OS X Mountain Lion. Do I need to reinstall all of my python packages now? If so is there an easy way to do this automatically?

Best Answer

OS upgrades from Apple tend to wreck havoc on Python installations, usually resulting in the re-installation of whatever packages you had installed. There is no way to fix it at this point, but going forward you could consider running virtualenv to keep your Python installs and packages separate from the OS.

A little more info can be found here.