2

Once upgraded from Lion Mountain to Mavericks (10.9.4), Trac installation stopped working.

First, I try to get it solved by upgrading the Trac installation, but I'm getting the following error message:

$ trac-admin /Users/myuser/Documents/2014/trac upgrade
Error: Cannot load Python bindings for PostgreSQL

Then, by testing directly on the Python console, I can say that this is consistent since I'm getting an equivalent error:

 $ python
 Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import psycopg2
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
     from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
 ImportError: dlopen(/Library/Python/2.7/site-packages/psycopg2/_psycopg.so, 2)
 Library not loaded: libssl.1.0.0.dylib
   Referenced from: /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
   Reason: image not found
 >>> 

I have already tried multiple approaches: installing and uninstalling psycopg2 (using pip and easy_install), or even building psycopg2 from sources.

Then, looking around for a solution, I have found some suggestions in these related questions Q1, Q2 and Q3, but without success yet.

otool, is giving me the following output:

$ otool -L /Library/Python/2.7/site-packages/psycopg2/_psycopg.so

/Library/Python/2.7/site-packages/psycopg2/_psycopg.so:
     libpq.5.dylib (compatibility version 5.0.0, current version 5.5.0)
     libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
     libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

Then, I have tried by setting the DYLD_FALLBACK_LIBRARY_PATH environment variable like this:

 $ echo $DYLD_FALLBACK_LIBRARY_PATH
 /Users/myuser/lib:/usr/local/lib:/lib:/usr/lib

Including, restart console and restart the machine, I'm running out of solutions, any idea how I can solve it?

Community
  • 1
  • 1
emecas
  • 1,586
  • 3
  • 27
  • 43
  • Do you have `brew` or similar installed? – Burhan Khalid Sep 28 '14 at 19:16
  • 1
    Might want to run brew update followed by brew upgrade might solve your ssl issue – Burhan Khalid Sep 28 '14 at 19:30
  • Thanks, I did it, but it's still same. This msg catches my attention, any idea? "The OpenSSL provided by OS X is too old for some software. Generally there are no consequences of this for you. If you build your own software and it requires this formula, you'll need to add to your build variables: LDFLAGS: -L/usr/local/opt/openssl/lib CPPFLAGS: -I/usr/local/opt/openssl/include" – emecas Sep 28 '14 at 20:22
  • 1
    Have you tried adding `/usr/local/opt/openssl/lib` to your `DYLD_FALLBACK_LIBRARY_PATH`? The message you shared in the comments indicates that your OpenSSL is being stored in `/usr/local/opt/openssl/lib`, which doesn't appear to be on your DYLD path. – TML Sep 28 '14 at 22:33
  • Curious, indirect and complementary solutions: The update/upgrade with 'brew' and then the correct setting up of DYLD_FALLBACK_LIBRARY_PATH variable. It's working now! Thanks to Burhan Khalid & @TML – emecas Oct 03 '14 at 17:42
  • You should post that as an answer to your own question, @emecas – TML Oct 03 '14 at 20:36

3 Answers3

1

Finally, I have been able to run Trac accessing my old tickets database stored in PostgreSQL 9.2

... After a couple of years of attempts, and a couple of upgrades from Mavericks to Yosemite and then to El Capitan, this has been the solution:

Step 1: Change owner of /usr/local folder

sudo chown -R $(whoami):admin /usr/local

Step 2: Update Path

PG_HOME=/Library/PostgreSQL/9.2
PATH=$PATH:$PG_HOME/bin

Step 3: Reinstall psycopg2

pip uninstall psycopg2
pip install psycopg2

Step 4: Update relative paths used by psycopg2

sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.2/lib/libpq.5.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
sudo install_name_tool -change libcrypto.1.0.0.dylib /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
sudo install_name_tool -change libssl.1.0.0.dylib /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
emecas
  • 1,586
  • 3
  • 27
  • 43
1

@Emerson deserves full credit for this solution, however, here is a script which fixes just the OpenSSL links in _psycopg.so regardless of how your system is configured. I have been going in loops for hours attempting to fix this to no avail, and his answer fixed it finally.

This finally worked for me and could be modified to be a somewhat-generic solution:

#!/bin/bash
echo Fixing psycopg2 links in Mac OS X ...
site_packages="$(pip show psycopg2 | grep Location | awk '{ print $2 }')"
openssl_lib="$(brew --prefix openssl)/lib"
sudo install_name_tool -change libcrypto.1.0.0.dylib "$openssl_lib/libcrypto.1.0.0.dylib" "$site_packages/psycopg2/_psycopg.so"
sudo install_name_tool -change libssl.1.0.0.dylib "$openssl_lib/libssl.1.0.0.dylib" "$site_packages/psycopg2/_psycopg.so"

It's basically @Emerson's solution but with the paths dynamically determined by your setup and brew's installation locations. You will need to have psycopg2 already installed along with pip and brew.

razzed
  • 2,653
  • 25
  • 27
0

I faced exactly the same problem and solved it by following the below mentioned steps:

STEP-1:

Check if you have openssl installed by writing openssl on the commandline:

>>openssl

If it starts, this means its installed in your system and you may skip STEP-2 and go directly to STEP-3.

STEP-2:

If openssl isn't installed, install it by:

brew install openssl

STEP-3:

Check the path of openssl lib on your machine. On my machine it was:

/usr/local/opt/openssl/lib/

STEP-4:

You have to simply include this path from STEP-3 by running following command:

export DYLD_LIBRARY_PATH=***YOUR OPENSSL PATH FROM STEP-3 HERE***

i.e in my case, the command with the STEP-3 path is:

export DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib/

Now run python and import psycopg2. I had no errors after following this recipe.

Ali Raza Bhayani
  • 3,045
  • 26
  • 20
  • how can i find the location of openssl on my machine ? is there anyway from terminal .ANswer : whereis openssl :D – Jean Raymond Daher Mar 09 '15 at 00:27
  • well it didn't work for me .. . File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 50, in from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID ImportError: dlopen(/Library/Python/2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib Referenced from: /Library/Python/2.7/site-packages/psycopg2/_psycopg.so Reason: image not found – Jean Raymond Daher Mar 09 '15 at 00:34