2009年9月18日星期五

Make psycopg2 and readline work in Snow Leopard with apple python

Upgrading to Apple 64-bit OS Snow Leopard, I found that have to re-configure my development environment. After bunch of google and try, finally I make postgresql, psycopg2 and (apple) python readline work in 64-bit. The postgresql is 8.3 from MacPort, psycopg2 installed from source and I'm using python ship with system.

First follows migration guideline to migrate macports (included postgresql 8.3). Then I found that psycopg2 can not be imported.

Symbol not found: _PQbackendPID

I found a solution from kreeger's blog that run system python in 32-bit mode, it works. However later I meet readline issue that it can not work with 32-bit python.

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

I can install readline successfully follows Zachary Voase’s blog, he provided a patched egg just works (I also try steps by steps, the same). Then I installed IPython, found readline can not recognize by the IPython, since import readline is failed. After switch back to 64-bit python, it works again. So I have to find a way to either make psycopg2 work with 64-bit python or make readline work with 32-bit python, I prefer the first one. So I got the 64-bit python back.

defaults write com.apple.versioner.python Prefer-32-Bit -bool no

Lucky enough by tracking Nick Takayama 's twitter, Here's a way to make psycopg2 work with 64-bit python.

First fetch psycopg2 source, extract it.

curl 'http://initd.org/pub/software/psycopg/psycopg2-2.0.12.tar.gz' -O
tar -xzf psycopg2-2.0.12.tar.gz
cd psycopg2-2.0.12/

Edit setup.cfg, set pg_config to correct path (I have multiple Postgresql installed).

pg_config=/opt/local/lib/postgresql83/bin/pg_config

To make sure I start from fresh, I also deleted related psycopg2 egg from /Library/Python/2.6/site-packages/, if you already build from source before, make sure delete build/ directory.

Then symbol link libpg.5.dylib to /usr/lib/

sudo ln -sf /opt/local/lib/postgresql83/libpq.5.dylib /usr/lib/libpq.5.dylib

Install psycopg2 from source.

sudo python setup.py install

If you run 'otool -L /Library/Python/2.6/site-packages/psycopg2/_psycopg.so' make sure that libpq is not listed in the output. Then try import it. Boom works for me.

Other solution: I also saw a solution to make an universal postgresql8x for x86_64 and i386, then manually build psycopg2. However I can not macport it successfully, I failed on building libxslt +universal. You can try it from Mads Sülau Jørgensen's blog.


2009年9月12日星期六

Replace Hard Drive for My Laptop

Follows the good guideline "How to clone Mac OS X to a new hard drive", I used SuperDuper to copy all data to the new hard drive then switch to it without a boot-able system DVD. It takes longer time than I thought, but it happens at night while I have a good sleep. It works!

2007年12月19日星期三

Upgrade T40 Laptop CPU

Since my Santa give me a really good gift rather than a MacBook, I have to continue use my old laptop IBM T40 with 1.3G PM and 512MB memory. Then I decide to upgrade it. It's really hard to find a mobile cpu with a reasonable price two years ago, however you can easy find one today. I order a Dothan 755 with 90nm 2.0G 400MHZ(Spec SL7EL), in 6xx RMB (a new one is around 9xx I guess). T40 mainboard can only support 400MHZ Dothan, A little pity.

If you have an old T40 as well, and want to upgrade to an Dothan, please notice that you have to order a stepping B1 version CPU (not C0). Otherwise you can only work in a low frequency. The reason is IBM T40 Embedded Controller don't update for a long time. The last update is Nov 2004, however C0 CPU is available in June 2005 ! So the best CPU you can buy should be 765 2.1G SL7V3. Or someday IBM update EC for the old T40.

The old cpu I plan to make a key ring :-)

2007年5月31日星期四

Google Developer Day 2007 snapshot

China joins the Google worldwide developer day, that's good. I has participated in the big party today. Though the rainy weather is cold, in the spot it's really hot. Google show it's great influence in china. There're 2 workshops, 9 speakers, and almost 500 developers here, sometime I even think need more O2.

I choose the workshop B the one talk about open source. I saw some interesting guys here, Jon Trowbridge, Mike Schroepfer, Suzhe, Jie Zhou(we discuss something about great firewall), and Guido. Some of them give simple speech, easy to understand.



Short talk with Guido, He said Django is his favorite web framework, good choices, we use it too. And I introduce him about Exoweb -- the growing company I worked for. He never heard of that, then he knows this time :-). The later today we have another short talk, I leave him our planet URL (http://planet.exoweb.net) on a custom name card. I guess he could get something really funny if he has time to visit. Anyway there's no time to do more communication with him. As the pop star here,
lots believers want to talk with him and someones like photos more then talking. Anyway it shows more people knows python, and they love it.

In the panel discussion people talk about how to make open source more popular in china. Seems very little Chinese open source project you can find today. Lots people think that's because Chinese programmer still fight for their food, lot's of them do extra work for their regular jobs. A question has been asked several times that

How you make money from open source?" or "When you contribute to open source? in evening? in weekend? or ...".
From the question you see Chinese programmer feel very interesting about why people do open source -- could you get any benefits? or you only do it because you're a rich guy? I think it's a 'GOOD QUESTION'. Actually I don't know how people get food from open source, however
  • open source is a kind of skill, you learn from it.
  • join in open source project is good experience just like you get for your pay-job.
  • for your company, open source can't make your client happy automatically, it's your job. but open source can save your money and time, it's free usually and agile(compare to some slow process).
And I also heard that google summer code pay something for student.



In the wrap-up reception after the normal speech, the organizer give people a little time to show their idea. I don't want to always to be a listener, I rob the microphone and share a few minutes. I tell them I like python and in Exoweb we use python. For Chinese open source I think it maybe not a good time to talk about how many contributors are there, but how many open source users are there. If people start to use open source for their daily job, it's quite natural to submit bug fixing, write blog, or translate something. Those are junior contribution but really useful. and someday an idea come out you can do some big changes. At the end I do a little advertisement for Exoweb, tell people we are hungry for smart guys. And Exoweb is a place to work if you want to combine your job and your interesting. hmm... I like google guys they don't prevent you do some free advertisement after your speech. Of course Google is another good choice, if they pay you 10 times than us :-0 just kidding...

I also meet one my old friend Jerry Ge, and a new friend Benjamin Collar( Say hi, Jerry and Benjamin). OK, say thanks to Google for the big party, it's a good day. Here some suggestions may help them next time:
  • provide power and faster network(bandwidth). we sit here all day, I'm sure my laptop will sleep.
  • change to use an strong contrast PPT template, suggest use big white text on black background. the current PPT items look like sands.
  • keep the air fresh, turn the air-condition colder.
  • maybe provide some PPT on live when speech begin.
  • maybe provide an IRC channel for each workshop, another way to collect questions.
  • I like the show time in wrap-up reception, keep it.