eclipse 在 Mac OS (Yosemite) 上使用 psycopg2 的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28515972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problems using psycopg2 on Mac OS (Yosemite)
提问by Benja Garrido
Currently I am installing psycopg2 for work within eclipse with python.
目前我正在安装 psycopg2 以便在 eclipse 中使用 python 工作。
I am finding a lot of problems:
我发现很多问题:
- The first problem
sudo pip3.4 install psycopg2
is not working and it is showing the following message
- 第一个问题
sudo pip3.4 install psycopg2
不起作用,它显示以下消息
Error: pg_config executable not found.
错误:找不到 pg_config 可执行文件。
FIXED WITH:export PATH=/Library/PostgreSQL/9.4/bin/:"$PATH”
固定:export PATH=/Library/PostgreSQL/9.4/bin/:"$PATH”
- When I import psycopg2 in my project i obtein:
- 当我在我的项目中导入 psycopg2 时,我得到:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so Library libssl.1.0.0.dylib Library libcrypto.1.0.0.dylib
导入错误:dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so 库 libssl.1.0.0.dylib 库 libcrypto.1.0.0.dylib
FIXED WITH:
sudo ln -s /Library/PostgreSQL/9.4/lib/libssl.1.0.0.dylib /usr/lib
sudo ln -s /Library/PostgreSQL/9.4/lib/libcrypto.1.0.0.dylib /usr/lib
固定:
sudo ln -s /Library/PostgreSQL/9.4/lib/libssl.1.0.0.dylib /usr/lib
sudo ln -s /Library/PostgreSQL/9.4/lib/libcrypto.1.0.0.dylib /usr/lib
- Now I am obtaining:
- 现在我得到:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _lo_lseek64 Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so Expected in: /usr/lib/libpq.5.dylib in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so
导入错误:dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so, 2):找不到符号:_lo_lseek64 引用自:/Library/Frameworks/Python .framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so 预期在: /usr/lib/libpq.5.dylib 在 /Library/Frameworks/Python.framework/Versions/3.4/lib /python3.4/site-packages/psycopg2/_psycopg.so
Can you help me?
你能帮助我吗?
回答by KungFuLucky7
You need to replace the /usr/lib/libpq.5.dylib library because its version is too old.
Here's my solution to this problem:
您需要替换/usr/lib/libpq.5.dylib 库,因为它的版本太旧了。
这是我对这个问题的解决方案:
$ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old
$ sudo ln -s /Library/PostgreSQL/9.4/lib/libpq.5.dylib /usr/lib
回答by Samer
If you are using PostgresApp, you need to run the following two commands:
如果您使用的是 PostgresApp,则需要运行以下两个命令:
sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old
sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib
回答by jgshurts
I was able to fix this on my Mac (running Catalina, 10.15.3) by using psycopg2-binary rather than psycopg2.
通过使用 psycopg2-binary 而不是 psycopg2,我能够在我的 Mac(运行 Catalina,10.15.3)上解决这个问题。
pip3 uninstall psycopg2
pip3 install psycopg2-binary
pip3 uninstall psycopg2
pip3 install psycopg2-binary
回答by ksmskm
I am using yosemite, postgres.app & django. this got psycopg2 to load properly for me but the one difference was that my libpq.5.dylib
file is in /Applications/Postgres.app/Contents/Versions/9.4/lib
.
我正在使用优胜美地、postgres.app 和 django。这让 psycopg2 为我正确加载,但一个区别是我的libpq.5.dylib
文件在/Applications/Postgres.app/Contents/Versions/9.4/lib
.
thus my second line was sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib
因此我的第二行是 sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib
回答by Dusk
Here's a fix that worked for me on El Capitan that doesn't require restarting to work around the OS X El Capitan System Integrity Protection (SIP):
这是一个在 El Capitan 上对我有用的修复程序,不需要重新启动即可解决 OS X El Capitan 系统完整性保护 (SIP):
brew unlink postgresql && brew link postgresql
brew link --overwrite postgresql
回答by Steve Forbes
For those of you on El Capitan who can't use @KungFuLucky7's answer - I used the following to fix the issue (Adjust paths to match yours where required).
对于那些在 El Capitan 上无法使用 @KungFuLucky7 的答案的人 - 我使用以下方法来解决问题(根据需要调整路径以匹配您的路径)。
sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.5/lib/libpq.5.dylib /usr/local/lib/python2.7/site-packages/psycopg2/_psycopg.so
回答by Hung Dam
In El Capitan, I used the same solution as @Forbze but 2 more commands as follows.
在 El Capitan 中,我使用了与 @Forbze 相同的解决方案,但还有 2 个如下命令。
sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.3/lib/libpq.5.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
sudo install_name_tool -change libssl.1.0.0.dylib /Library/PostgreSQL/9.3/lib/libssl.1.0.0.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
sudo install_name_tool -change libcrypto.1.0.0.dylib /Library/PostgreSQL/9.3/lib/libcrypto.1.0.0.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
It works perfectly!
它完美地工作!
回答by carlos.rivera
well, I'd like to give my solution, the problem is related with the version of c. So, I just typed:
好吧,我想给出我的解决方案,问题与c的版本有关。所以,我只是输入:
CFLAGS='-std=c99' pip install psycopg2==2.6.1