Question

I have created an application in Python that is tested and runs perfectly on my computer (Mac OSX 10.8.3 Python2.7.3 Postgresql9.2.4 Psycopg2-2.5). The app is compiled using py2app, and I can see that the build successfully included all packages/modules into the application contents folder.

Psycopg2 imports correctly on my machine, and the app runs fine, but when the application runs on another computer (I've tried 4 different computers...), it fails to open, and the console message reads an ImportError: dlopen(/Applications/app.app/Contents/Resources/lib/python2.7/psycopg2/_psycopg.so, 2): Library not loaded: libpq.5.dylib

I have searched and modified my code extensively through S.O. and Google to no avail. The psycopg2 links also do not specifically address this issue. http://initd.org/psycopg/articles/2010/11/11/links-about-building-psycopg-mac-os-x/

I have removed and reinstalled psycopg2 & postgresql numerous times, building from source, macports, homebrew, etc. My current environment is listed above, with postgresql 9.2.4 installed with homebrew, and psycopg2-2.5 installed from source while explicitly linking the pg_config location in the setup.cfg

When I run an otool -l on _psycopg.so, I get the following

/usr/lib/libpq.5.dylib (compatibility version 5.0.0, current version 5.4.0)
/usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 47.0.0)
/usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 47.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

How can my built application include (or point the target user to the files if available) these files? Is this the correct approach? Py2app of course will not include system files from /usr/lib/ in the "frameworks" option.

Was it helpful?

Solution

Your copy of _psycopg.so is linked with the system installation of libpq, not the libpq from the home-brew build of postgresql 9.2.4.

Because of this your application will only work on systems running OSX 10.8.

The solution is to rebuild psycopg2 and make sure that it is linked to the home-brew build of PostgreSQL.

Note that py2app will not copy files from /usr/lib into application bundles, even when explicitly told to include a shared library, because it assumes that files in /usr are system files and redistributing those is at best dodgy w.r.t. licenses.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top