Import psycopg2 Library not loaded: libssl.1.0.0.dylib

前端 未结 20 2422
囚心锁ツ
囚心锁ツ 2020-11-28 21:02

When I try to run the command:

import psycopg2

I get the error:

ImportError: dlopen(/Users/gwulfs/anaconda/lib/python2.7/si         


        
相关标签:
20条回答
  • 2020-11-28 21:51

    Simple solution: this pip command will install a package at a specific location:

    pip install psycopg2-binary -t PATH
    

    Where PATH is a path that you specify.

    To test this, install the package in a folder on your desktop. Then put a python script in the same folder that will import psycopg2. It should work with the script being in the same location as the psycopg2 package.

    Comments:

    This reason we need psycopg2-binary, according to old documentation that I found online:

    "The binary packages come with their own versions of a few C libraries, among which libpq and libssl , which will be used regardless of other libraries available on the client: upgrading the system libraries will not upgrade the libraries used by psycopg2 . Please build psycopg2 from source if you want to maintain binary upgradeability."

    Source: https://access.crunchydata.com/documentation/psycopg2/2.7.3/install.html#install-from-source

    I realized the issue has been that python's site package directory needs to be referenced. The location for this on my computer is:

    /Users/my_name/Library/Python/3.7/lib/python/site-packages
    

    Now, if you want to use IDLE or say PyCharm as I have been, the installation of psycopg2-binary needs to target this site directory. Additionally, you'll find two folders that appear after installing psycopg2-binary called: psycopg2, psycopg2_binary-2.8.4.dist-info

    I spent a long time investigating this issue. The other methods out there were not not resolving the issue as seen above regarding lib ssl and reason image not found.

    Setup: macOS Catalina, Python 3.7, PyCharm/IDLE project on Desktop, openssl@1.1/1.1.1d

    0 讨论(0)
  • 2020-11-28 21:53

    My flavor of setup was a little different than the OP: I'm using Postgres.app on Mac and am within a virtualenv; but the symptoms were similar.

    For me, this occurred right after updating my Postgres.app from 9.3 to 9.5 on my local, and the error clearly showed the psycopg2 path for libssl.1.0.0.dylib was pointing to the old 9.3 data directory location (the image referenced in this error?). Adding weird things to my ENV or removing symlinks I'm not sure the impact of definitely didn't feel right to me. I solved it by uninstalling then re-installing psycopg2 the same way I had when it was working - something that doesn't feel very dangerous at all:

     # In my virtualenv
     pip uninstall psycopg2
     pip install psycopg2
    

    Then I was all good!

    0 讨论(0)
提交回复
热议问题