0

I have been stuck on this issue for some time. After struggling to install psycpg2 on my Mac I got a friend to help me install it using this:

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip3 install psycopg2

I then imported psycopg2

I tried to run my db program and got this error:

Traceback (most recent call last):
  File "postgresdemo.py", line 1, in <module>
    import psycopg2 
  File "/Users/nkosana/Library/Python/3.7/lib/python/site-packages/psycopg2/__init__.py", line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
ImportError: dlopen(/Users/nkosana/Library/Python/3.7/lib/python/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Symbol not found: _PQencryptPasswordConn
  Referenced from: /Users/nkosana/Library/Python/3.7/lib/python/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
  Expected in: /usr/lib/libpq.5.dylib in /Users/nkosana/Library/Python/3.7/lib/python/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so

System and versions

MacOS Catalina (10.15.4)

psycopg2-2.8.5

Python 3.7.3

I would appreciate your help, thanks in advance.

2 Answers2

0

I had the same problem you are having:

Symbol not found: _PQencryptPasswordConn
  Referenced from: /Users/Lynda/pgproject/pgprojectenv/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
  Expected in: /usr/lib/libpq.5.dylib

What worked for me is adding /usr/local/lib to the PATH and create a symbolic link from my PostgreSQL/lib to /usr/local/lib

cd /usr/local/lib
ln -s /Users/Lynda/PostgreSQL/lib/libpq.5.12.dylib ./libpq.5.dylib

There is an answer that fixes this lib error and better explains why this is happening and how to fix it here Mac OS X Lion Psycopg2: Symbol not found: _PQbackendPID

bgar2021
  • 1
  • 1
0
pip uninstall psycopg2
pip install psycopg2

From here, worked for me. macOS Catalina version 10.15.7. Python 3.5.9

Q. Qiao
  • 607
  • 4
  • 16