Python, cygwin, TurboGears, mysql hell

· Read in about 4 min · (739 words) ·

Ok - here goes - I’ve always liked python, though definitely a noob. I was interested in python on the web and after a bit of googling, seems like TurboGears is the way to go.

First things first - decided to use mysql as the database (already have it on my machine and didn’t want to install one more database (postgresql/sqlite). Now it turns out that MySQL doesnt have a cygwin package. More googling - mysql server can’t run on cygwin due to something to do with pthreads. You can compile the mysql client on cygwin though.

That’s what I decided to do - grabbed the Linux tar.gz source from, got it into a directory and ran ./configure --without-server, followed by make && make install. All went through fine -other than the fact that it was time consuming and pretty boring (more so since I had to download and install gcc, bintools first in cygwin)

I thought I’d got through the hard part and what remained was to install python-MySQLdb package. Off I went to

easy_install MySQLdb

No luck there - package build failed with missing library -lmysqlclient_r. Turns out that the 'thread-safe' version of mysql client (mysqlclient_r) is preferred but the mysql build doesnt build this by default. What a shame!!!

Anyway, so I wasnt going to redo the whole mysql client library build again - more README files and googling later, grabbed mysql-python-1.2.2 tarball, got it into a folder, edited site.cfg and changed 'threadsafe=false'. The next run on python build worked properly, with the python mysql linking against the non threadsafe mysqlclient library.

Think troubles are over yet? No way.

Off I went to test - started the python interpreter and did a import MySQLdb, and got a Permission Denied in some 'egg' file!!! What the heck are these egg files anyway. Well, I did’nt have much of a clue and more google later got educated that these are install packages used by the easy install system. The more I looked, the more it seems that the easy install is anything but easy :(. Anyway, this one had me floored - since I couldnt get to the line of source where the error was and had no clue how to view the contents of an 'egg' (they’re zips - but I didnt know that and very helpfully there’s hardly anyplace where they say that they’re zips with the extension of egg!!! Baaah!! - why couldn’t they just use .zip?)

More and more hard googling - and this time the info’s really sketchy till eventually found a post from a guy who asked the exact same question. Guess what, the easy_install system unzips the eggs to some folder (pointed by PYTHON_EGG_CACHE env var) and there I needed to do a chmod a+x on the _mysql.dll. Well so I did echo $PYTHON_EGG_CACHE and the var isnt set!!! Admittedly at this point, I’m not looking sharp either - what started out as a quick spin has become a quagmire of installation issues - but I’ll be damned if I let it sink me!!! Eventually, had the Eureka moment and checked ~/.python-eggs and sure enough found the truant _mysql.dll. Quick chmod a+x and presto - import MySQLdb worked!!! YAHOOOOOOOOOOOOOOOOOOOO!!!!

And now back to where I started - went back to turbogears, did a tg-admin quickstart, setup a mysql database and started with python Guess what - no luck yet - turns out that mysql cant client to my windows server with a socket.

More googling - and this time its really desperate - and more enlightenment - the windows mysqld doesnt do unix sockets - how do I force tcp/ip? Simple - use as hostname in the connection settings instead of localhost!! Finally something that was easy to fix. Finally after 8 hours of on and off hacking away at installation issues I’m glad to see a turbogears web page.

Bottomline: Python’s great, from the looks of it, turbo gears seems well designed. Mysql is a great database - a cygwin native server would be great - or atleast a client package. But if one has to run through all these hoops just go get a 'quick spin' then adoption’s going to be difficult.

I havent tried RoR - but has someone tried a similar thing on cygwin (cygwin, ruby, RoR, mysql)? How does the experience compare - is it any easier to get off the ground?