ImportError: dlopen(/Users/me/sites/env/trackmap/lib/python2.7/site-packages/...
我尝试使用pip在virtualenv中安装psycopg2,编译看起来不错,它说“成功安装psycopg2”,但当我尝试在python解释器中导入它(在virtualenv中),它显示错误:File "<stdin>", line 1, in <module>
File "/Users/me/sites/env/trackmap/lib/python2.7/site-packages/psycopg2/__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Users/me/sites/env/trackmap/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.dylib
Referenced from: /Users/me/sites/env/trackmap/lib/python2.7/site-packages/psycopg2/_psycopg.so
Reason: Incompatible library version: _psycopg.so requires version 1.0.0 or later, but libssl.0.9.8.dylib provides version 0.9.8
错误是说libssl。dylib版本太老了?在我的mac上,错误是libssl.dylib 和 libcrypto.dylib 太旧了,pyscopg无法使用。mac使用的openssl包是0.98,pyscopg需要1.0.0或更高版本。我的解决方案是:
install openssl from brew
brew install openssl
copy libssl.1.0.0.dylib and libcrypto.1.0.0.dylib from /usr/local/Cellar/openssl/1.0.1c to /usr/lib/
cd /usr/local/Cellar/openssl/1.0.1c/lib
sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/lib/
in /usr/lib directory, make a softlink libssl.dylib and libcrypto.dylib.
sudo rm libssl.dylib libcrypto.dylib
我也有类似的问题。我曾经用Anaconda安装python和一些包,后来用pip安装psycopg2。我可以通过卸载psycopg2并使用conda package manager(而不是pip)重新安装它来修复这个错误。
pip uninstall psycopg2
conda install psycopg2
brew install openssl
找到openssl brew libs的位置,从目录/usr/local/Cellar/openssl.开始搜索
在我的例子中是在/usr/local/Cellar/openssl/1.0.2d_1/lib中
最后设置DYLD_LIBRARY_PATH,即在.bash_profile中添加这样一行:
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/Cellar/openssl/1.0.2d_1/librestart shell,
或者直接源代码~/.bash_profile
如果你正在使用postgres系统安装程序(而不是postgres .app),请使用:export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.3/ liblib5,它可以放在~/中。
如果你使用PostgresApp,设置DYLD_LIBRARY_PATH环境变量,例如:
DYLD_LIBRARY_PATH=/Applications/Postgres.app/Contents/MacOS/lib/ ../venv/bin/python manage.py syncdb
页:
[1]