Psycopg2 image not found

后端 未结 20 1543
无人及你
无人及你 2020-11-29 18:04

Trying to setup postgres with the postgres mac app and hit this error, which I haven\'t been able to solve. Any thoughts?

    ImportError: dlopen(/Users/Crai         


        
相关标签:
20条回答
  • 2020-11-29 18:38

    Big picture, the problem is that a required library couldn’t be found. You can alter where psycopg2 looks for libssl using Apple’s open source compiler tools, otool and install_name_tool. These ship with OS X, and manual pages are available with man <command>.

    Change into the psycopg2 module directory mentioned in the error message. Once there:

    $ otool -L _psycopg.so
        ...
        @executable_path/../lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
        ...
    

    This lists the libraries _psycopg2.so will look for. You can change where it’ll look with install_name_tool:

    $ install_name_tool -change @executable_path/../lib/libssl.1.0.0.dylib /usr/local/opt/openssl/lib/libssl.1.0.0.dylib _psycopg.so
    

    You’ll need to adjust for where you have libssl.1.0.0.dylib, of course. The example I gave is the default Homebrew path, but you might have it from Anaconda and/or the PostgreSQL app bundle. (brew install openssl if you don’t have it yet.) You’ll also likely need to repeat for libcrypto.

    Executing this change may fail depending on how _psycopg2.so was built. If that happens, you could probably build the module yourself with custom library paths, but I won’t get into that.

    This approach has the advantage of being narrower, and thus less risky, than the approach (given in other answers here) of linking libssl 1.0.0 into dyld’s search paths (either through ln -s or setting a DYLD_* environment variable). (See warnings against these approaches in a pair of discussions and some code. Learn more about dyld through man dyld.) It has the disadvantage of needing to be repeated for each copy of psycopg2. Choose your own adventure.

    Disclaimer: Most of the content in this answer is from knowledge I cobbled together in one day. I am no expert.

    0 讨论(0)
  • 2020-11-29 18:39

    Under Mac OS X 10.11 (El Capitan), /usr/lib is read only for root user. You'll get a ln: /usr/lib/libssl.1.0.0.dylib: Operation not permitted error You need to use /usr/local/lib instead of /usr.

    $ sudo ln -s /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/local/lib
    $ sudo ln -s /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/local/lib
    
    0 讨论(0)
  • 2020-11-29 18:40
    $ sudo ln -s /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/lib
    $ sudo ln -s /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/lib
    

    I encountered this error while working on Django. I have it working on virtualenv with Django==1.3 but not on Django==1.5 where I have to issue the commands above.

    In OS X El Capitan you can't do these links without disabling system protection but it works well if you link to /usr/local/lib

    0 讨论(0)
  • 2020-11-29 18:41

    This happened to me after upgrading Postgresql, and after installing psycopg2 in my virtualenv. Reinstalling (re-building) worked for me.

    pip uninstall psycopg2
    pip install psycopg2
    
    0 讨论(0)
  • 2020-11-29 18:41

    I found this solution that worked for me

    sudo cp /Applications/Postgres.app/Contents/Versions/9.3/lib/libssl.1.0.0.dylib /usr/lib
    sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib 
    
    sudo cp /Applications/Postgres.app/Contents/Versions/9.3/lib/libcrypto.1.0.0.dylib /usr/lib
    sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib 
    

    Replace this part '/Applications/Postgres.app/Contents/Versions/9.3/' depending upon the location where psql is installed on your machine. Command to find where psql is installed :which psql

    UPDATE FROM COMMENTS: On OSX 10.11 (El Capitan), you can no longer copy files to /usr/lib. Use /usr/local/lib

    0 讨论(0)
  • 2020-11-29 18:44

    In your bash environment before you load it, try this:

    export DYLD_LIBRARY_PATH=/Library/PostgreSQL/x.y/lib
    

    ..replacing the 'x.y' with the version on your system.

    ..be aware that setting this in your bash profile can interfere with other programs, as KindOfGuy noted.

    ..of course, if you're not running it from a bash prompt, you'll have to set up your environment in whatever way pyenv lets you. ..you could even edit pyenv itself and place that at the top.

    Another alternative is to put this in a python script which runs before you attempt to import psycopg2:

    import os
    os.environ['DYLD_LIBRARY_PATH'] = '/Library/PostgreSQL/x.y/lib'
    

    ..again, replacing 'x.y' with the version on your system in /Library/PostgreSQL.

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