Adventures in Python Compatibility

For one of my latest projects, I needed to install a fair amount of python packages. Granted pip (Python package installer) makes it super easy to install packages, this time it was not as straightforward as it normally is.

Psycopg2 (PostgreSQL database adapter for Python) was the package I had the most problems with. The reason I had those issues was that python was running in 64bit mode and PostgreSQL was a 32bit package, so to python it looked like PostgreSQL was not installed. I was finally able to install psycopg2 by overriding the archs like so:

sudo env ARCHFLAGS="-arch i386 -arch x86_64" pip install psycopg2

Lesson learned – check the bit version.

If you’d like to check what bit version your python is running, just type this command in your python interpreter:

import sys
sys.maxint

if it is a 64bit that you will see – 9223372036854775807, and for 32bit version, it will be – 2147483647.

there is another way to check the version, but I found it to be unreliable under Mac OSx:

import platform
platform.architecture()

in my case, the output was ’64bit’ before AND after dropping python into the 32bit mode.

To switch python from 64bit version into 32bit one, I executed the following command:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>