psycopg2 import error due to failure to load libraries

為{幸葍}努か 提交于 2019-12-25 03:47:33

问题


I have tried many ways of installing psycopg2 after having installed PostgreSQL using the one-click installer, but anyway I try confronts me with the same import error in python: ImportError: dlopen(/Library/Python/2.5/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libpq.5.dylib Referenced from: /Library/Python/2.5/site-packages/psycopg2/_psycopg.so Reason: image not found

I am on Mac OS X 10.5.8. I am using Python 2.5. I installed PostgreSQL from the installer (I did not port it) and it installed in /Library). I added /Library/PostgreSQL/9.1/bin to the setup.cfg of the source psycopg2, as instructed in the INSTALL file and everywhere on the internet and then ran sudo python setup.py build and then sudo python setup.py install. I also tried exporting /Library/PostgreSQL/9.1/bin to my path instead and running sudo pip install psycopg2. But the exact same problem occurred in all of these scenarii. I would greatly appreciate some help with this.

Best Marion


回答1:


The problem is that at runtime the libpq.5.dylib file can't be found because it is not in one of the default locations searched by the dynamic (runtime) linker. Try to define the environment variable DYLD_LIBRARY_PATH before launching python. I am no MacOS X expert but something like:

export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.1/lib

will probably work.



来源:https://stackoverflow.com/questions/14863723/psycopg2-import-error-due-to-failure-to-load-libraries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!