Fixing the Leopard install of Python, and virtualenv for the win.

by jesse in ,


So, as a followup to my previous post - PyObjc 2: Leopard, Python 2.5.1 and You. A commenter pointed out that the python.org installation of python only adds a new version of Python to the /Library/Frameworks/ directory - it does not replace the default one in /System/Library/Frameworks/. So, in order to "return" to my "pristine" leopard state, all I actually had to do was remove this line in my .bash_profile (which I hadn't noticed - my .bash_profile is about 250 lines long): PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}" Then I simply moved the /Library/Frameworks/Python.framework directory to some other name (just to be anal). The only side-effect being that I "lost" all of my installed python modules in the python.org install's site-packages directory.

The latter is fine, because I've been meaning to 'clean house' with the cruft I've built up compulsively downloading stuff from pypi and doing other work. Since I'm now dealing with a 'cleaned out' version, I took the chance to clean-install virtualenv and setup a nice /jesse/python_vms directory. I added a 'default' profile that gets auto-loaded on login, and added a few functions to let me switch in-between them. Example: # Python VMs override(s) VMDIR="/Users/jesse/python_vms" DEFAULT_PY_ENV="$VMDIR/default" SANDBOX_PY_ENV="$VMDIR/sandbox" # Load the default python env by, uh, default! . $DEFAULT_PY_ENV/bin/activate pydefault () { . $DEFAULT_PY_ENV/bin/activate; } pysandbox () { . $SANDBOX_PY_ENV/bin/activate; }

In my case, the default profile will only load my work-profile, while my sandbox is going to be where all the pypi modules I tinker with go. The nice thing of course, is that the activate script included with the virtualenv env overrides my default $PATH to make sure the local bin directory is used prior to the main $PATH, which means I don't need to worry about conflicts with the default easy_install that comes with Leopard.

Now I've got the best of all worlds, the default install that has all the leopard pyobjc goodies, and a nice clean sandbox.

Of course, this doesn't even cover the horror which is my /subversion directory - which at last look, I had to write a shell-script wrapper to auto-update the largish number of svn projects I watch/sync.