无法让psycopg2工作,但安装正确。 Mac OS

时间:2016-10-12 14:58:07

标签: python macos psycopg2

我试图在Mac上本地使用psycopg2。它安装得很好,至少没有错误,但是当我导入它时会收到一条错误消息。

我已经看到了数十个具有类似问题和解决方案的线程,这些线程大量变化,对于这样一个常见模块而言似乎过分。

任何人都可以帮忙吗?

Last login: Wed Oct 12 15:47:24 on console
Gurmokhs-MBP:~ Gurmokh$ pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in     /Library/Python/2.7/site-packages
Gurmokhs-MBP:~ Gurmokh$ python
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 12:54:16) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File     "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/psycopg2-2.6.2-py2.7-macosx-10.6-intel.egg/psycopg2/__init__.py",     line 50, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME,    ROWID
ImportError:     dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site    -packages/psycopg2-2.6.2-py2.7-macosx-10.6-    intel.egg/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from:     /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/psycopg2-2.6.2-py2.7-macosx-10.6-intel.egg/psycopg2/_psycopg.so
  Reason: image not found
>>> ^D
Gurmokhs-MBP:~ Gurmokh$ 

我可以看到一些来自不同应用程序的副本。 我假设我可以复制其中一个。上面的消息告诉我什么是引用此文件,但它们并没有告诉我他们期望找到它。如果我知道它应该去哪里,我会尝试这个。

bash-3.2# find . -name "libssl.1.0.0.dylib"
./Library/Application Support/Fitbit Connect/libssl.1.0.0.dylib
./Library/PostgreSQL/9.5/lib/libssl.1.0.0.dylib
./Library/PostgreSQL/9.5/pgAdmin3.app/Contents/Frameworks/libssl.1.0.0.dylib
./Users/Gurmokh/.Trash/Navicat for PostgreSQL.app/Contents/Frameworks/libssl.1.0.0.dylib

1 个答案:

答案 0 :(得分:1)

谢谢你们。

@maxymoo我接受了你的建议。我已经安装了anaconda2。安装更新了我的路径include / anaconda / bin。

然后使用导航器我安装了pyscopg2。现在我可以在shebang中使用它,我的脚本执行得很好,我可以导入这个模块。

Gurmokhs-MBP:rest Gurmokh$ python
Python 2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul  2 2016, 17:43:17) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import psycopg2
if psycopg2.connect("dbname='postgres' user='postgres' host='localhost'"):
...     print "connection made"
... 
connection made
>>>