安装psycopg2后,我无法正确导入它

use*_*520 5 terminal psycopg2 dlopen importerror python-3.x

当我尝试使用以下简单的代码行导入 psycopg2 时:

import psycopg2
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psycopg2/__init__.py", line 50, in <module>
    from psycopg2._psycopg import (                     # noqa
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libssl.1.1.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
  Reason: image not found
Run Code Online (Sandbox Code Playgroud)

有人知道为什么会发生这种情况吗?

Ser*_*kiy 13

我也遇到过同样的问题。在深入研究了 @singingstone 提供的线程后,对我有用的解决方案是pip uninstall psycopg2,然后pip install psycopg2-binary