Library not loaded: libpq.5.dylib
Asked Answered
M

2

25

I have app that is running Ruby 1.9.2, Rails 3, and postgreSQL 8.3. It was originally setup and working with postgreSQL 9.1, but I uninstalled 9.1 and installed and changed to 8.3 insure compatibility on a Heroku shared database setup. It was running ok, but it's not now

Now, when working on this app, when I run a database upgrade I get this error:

dlopen(/Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib
  Referenced from: /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle
  Reason: no suitable image found.  Did find:
    /usr/lib/libpq.5.dylib: no matching architecture in universal wrapper - /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle

And when I try to run the server I get this error message:

/Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg.rb:4:in `require': dlopen(/Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib (LoadError)
  Referenced from: /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle
  Reason: no suitable image found.  Did find:
    /usr/lib/libpq.5.dylib: no matching architecture in universal wrapper - /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg.rb:4:in `<top (required)>'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
    from /Users/michaeljmccoy/www/mikemccoy/config/application.rb:7:in `<top (required)>'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:53:in `require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:53:in `block in <top (required)>'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:50:in `tap'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I know they are very similar errors and probably has to do with a missing path. However, when I add the path to my .profile file and restart the terminal window, I get the same errors.

Marcel answered 7/2, 2012 at 19:35 Comment(5)
Your PATH controls where the shell looks for executables. Your LD_LIBRARY_PATH controls where the shell looks for libraries. That said, this looks to me like your pg gem was compiled against a different PostgreSQL library version than the one you have now. You probably just need to reinstall pg.Cornet
I removed the current pg gem and am trying to reinstall, however I am getting what seems to be a pretty common error regarding missing postgres libraries. Here is what I am seeing: 'checking for pg_config... yes Using config values from /Library/PostgreSQL/8.3/bin/pg_config checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for pg_config_manual.h... yes checking for PQconnectdb() in -lpq... no checking for PQconnectdb() in -llibpq... no checking for PQconnectdb() in -lms/libpq... no Can't find the PostgreSQL client library (libpq) *** extconf.rb failed ***Marcel
I remember having to solve this at some point in the past, and it amounted to having to manually supply flags to the gem builder to tell it where to look for headers and libraries, but I don't have the info on-hand right now.Cornet
hmmm. ok, i will look at doing that. if you do happen to come across what you did and would be willing to share that would be great. Thanks again for pointing me in the right direction. Much appreciated.Marcel
To anyone who's found this question because you're experiencing this dylib issue on Mac OS X Mavericks and you're using PostgresApp: please see my answer to the related question here: https://mcmap.net/q/538298/-installing-pg-gem-error-failed-to-build-gem-native-extension. Basically I needed to go as far back as version 9.2.2.0 of the Postgres App in order to get this working. Thanks @jhiro009 for pointing me in the right direction - version 9.2.4.3 simply didn't work for me on Mavericks.Felicio
L
54

You may need to remove and re-install the pg gem, so it's compiled against the correct version of Postgres.

Latricelatricia answered 8/2, 2012 at 14:9 Comment(4)
If this doesn't help you, you may want to see this question: #15512637Richy
This solution works also with Django, just reinstall psycopg2 in the virtualenv.Guessrope
This worked for me as well.Micronutrient
Ran into this after a brew upgrade. I ran 'gem uninstall pg' and then re-ran 'bundle install' (pg was in my Gemfile). Worked!Silurid
A
4

For anyone seeing this error and running PostgresApp, this is a known problem that was fixed in version 9.2.4.3:

Discussion: https://github.com/PostgresApp/PostgresApp/issues/109

Installer: https://github.com/PostgresApp/PostgresApp/releases/tag/9.2.4.3

Of course, you could just grab the latest version (http://postgresapp.com/). Both versions got me back up and running with Rails 3.2.14 and Ruby 2.0.0. However, note that when I installed 9.2.4.3 my databases were still listed in psql, but when I installed 9.3.0 (the current version at the moment), my databases were no longer listed.

Aec answered 20/10, 2013 at 21:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.