TurboGears, IDE’s and Snow Leopard
I just spent two weeks playing with the Wing Python IDE and while it’s nice and probably actually better for Python development (as it is expressly designed for Python Development) than Eclipse (which was more Java intended) it has three things I couldn’t get past:
1. Wing runs on X and despite trying to muck around with it, it was just too “not native” on the Mac. The window colors bothered me, the customized perspective I configured would lose the secondary windows all the time and the fonts were horrible.
2. It isn’t Eclipse. The PyDev add-on for Eclipse just works, and I prefer PyDev’s code sense. And Eclipse feels more natural to me. Granted, I’ve been using Eclipse (a’la Adobe’s Flex Builder 3 and PyDev) for the last 18 months but…
3. I’m a cheap bastard. Eclipse is free, Wing isn’t.
So there you go.
I tried Wing because supposedly it handles multi-threaded debugging which, since we’re developing on the TurboGears framework, is a nice to have. But then I found Kees van den Broek’s handy howto on getting Eclipse and TurboGears 2 working together. This was timely because I had also, during this period, upgraded my laptop to Snow Leopard.
Now, Snow Leopard is fantastic. Faster, smaller, and all around better than Leopard except for one thing. If you’re a Python developer it makes like hell because Apple builds Snow Leopard with 1) Python 2.6.1 which is 2) compiled with a different version of GCC than Python.org uses. The issue was compounded further by the fact that in the last two years a couple other Python builds had been installed that I a) forgot about or b) didn’t realize were installed in parallel. Also, MacPorts and Snow Leopard weren’t altogether in sync [yet] which was installing Python 2.5 components and it was a mess… I removed MacPorts and tried Fink and then went right back to MacPorts but that’s another story.
Anyhow… long story shorter. Here’s my suggestion for making life easier with Python Development on OSX:
Python
1. The default Python build on OSX /System/Library/Frameworks/Python.framework. Now you know. Just ignore it and never touch it.
2. Next, ignore the MacPorts vs. Fink debate and install the latest version of MacPorts. Follow the great directions on the MacPorts site and make sure you do the selfupdate after the install.
3. Install the Python port, specifically the universal variant.
sudo port install python26 +universal
This will take awhile because MacPorts compiles everything locally and downloads an assload of dependencies. Here’s the important bit, MacPorts installs everything including itself to /opt/local/*. More importantly, your brand new Python build has been installed to /opt/local/Library/Frameworks/Python.framework with symlinks to your fresh python interpreter in /opt/local/bin
4. MacPorts seems to usually do this for you but just check that .profile and/or .bash_profile have the path you need :
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
if not you can edit these like so:
nano /Users/your_user_name/.profile
nano /Users/your_user_name/.profile
5. Install Python Setup Tools:
sudo port install py26-setuptools
6. Install virtualenv:
sudo easy_install virtualenv
Eclipse (This is a sight variation from KVDB’s I mentioned above)
1. Assuming you already have Eclipse installed as well as the PyDev module, create a development workspace. From a Terminal window :
mkdir pydevworkspace
2. From Eclipse, create a new PyDev project.
File –> New –> PyDev Project and click Finish - We’ll finish setting up the project in eclipse in a minute
3. Back in your terminal window, create a new project directory under pydevworkspace:
cd pydevworkspace
mkdir projectname
3. Create a virtualenv on your new project directory:
cd projectname
virtualenv –no-site-packages env
(so you now have a directory structure ../pydevworkspace/projectname with /src and /env subdirectories)
4. Activate the virtual environment:
source env/tg2/bin/activate
5. Install your Python modules, in my case TurboGears 2:
easy_install pip
pip install -e svn+http://svn.turbogears.org/trunk
pip install -e svn+http://svn.turbogears.org/projects/tg.devtools/trunk
Please Leave a Reply
TrackBack URL :