When I try to run the command:
import psycopg2
I get the error:
ImportError: dlopen(/Users/gwulfs/anaconda/lib/python2.7/si
After trying for more than a day I came to the below solution.
Similarly, if you face issue for Library not loaded: libssl.1.0.0.dylib just change the version from 1.0 to 1.1 of openssl and copy libssl.1.1 instead libssl.1.0 and libcrypto.1.1 instead libcrypto.1.0.0
Done you are all set to enjoy psycopg2 in mac.
I had the same problem when I updated openssl
from 1.0.0
to 1.1.1d
, and this fixed my problem:
brew upgrade postgresql
After bashing my head against the wall for a couple hours, these two solutions are guaranteed to work:
Option 1. This solves our problem without messing around with environment variables. Run this in your shell:
brew install --upgrade openssl
brew unlink openssl && brew link openssl --force
Boom! This upgrades the symbolic links in /usr/local
for libssl
and libcrypto
. Now import psycopg2
works like a charm.
Option 2. If for some reason you would like to maintain the current symbolic links in usr/local
, run this command in your shell:
export DYLD_FALLBACK_LIBRARY_PATH=$HOME/anaconda/lib/:$DYLD_FALLBACK_LIBRARY_PATH
Just make sure to replace $HOME/anaconda/lib
above with the actual lib path. In my case, this was $HOME/miniconda2/envs/ali/lib
.
This will only work for the shell/bash session you're currently in. To make the change persistent, add the export
statement to your ~/.bash_profile
or ~/.bashrc
file.
Thoughts: IMO #1 is the proper way to deal with this problem, but I left #2 in case some people prefer working with environment variables rather than fixing symbolic links (if, for example, they have software with a dependency on the older openssl file versions).
In relation to X.L.'s answer above, I didn't want to use Anaconda when I'm already using pip, so I just gave it the path to the Postgres libraries which worked for me (I'm using PostgreSQL.app on Mac OS 10.10)...
export DYLD_FALLBACK_LIBRARY_PATH=/Library/PostgreSQL/9.5/lib:$DYLD_FALLBACK_LIBRARY_PATH
Homebrew upgrades default openssl from v1.0 to v1.1. If you tried @Scott solution to upgrade openssl:
brew install --upgrade openssl
brew unlink openssl && brew link openssl --force
you may run into ssh problem. You need to upgrade openssh as well.
brew upgrade openssh
according to this blog: https://blog.junjizhi.com/all/2019/12/17/git-fetch-libssl-error.html
After Homebrew wouldn't allow me to force link openssl
the following worked fine:
pip install --global-option=build_ext \
--global-option="-I/usr/local/opt/openssl/include" \
--global-option="-L/usr/local/opt/openssl/lib" psycopg2
(this installation succeeded in a virtualenv
on macOS)