2

I'm trying to get Django running on OS X Mavericks and I've encountered a bunch of errors along the way, the latest way being that when runpython manage.py runserver to see if everything works, I get this error, which I believe means that it misses libssl:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: @loader_path/../lib/libssl.1.0.0.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so Reason: image not found

I have already upgraded Python to 2.7.6 with the patch that handles some of the quirks of Mavericks.

Any ideas?

Full traceback:

Unhandled exception in thread started by > Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 93, in inner_run self.validate(display_num_errors=True) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 280, in validate num_errors = get_validation_errors(s, app) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/validation.py", line 28, in get_validation_errors from django.db import models, connection File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/init.py", line 40, in backend = load_backend(connection.settings_dict['ENGINE']) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/init.py", line 34, in getattr return getattr(connections[DEFAULT_DB_ALIAS], item) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 93, in getitem backend = load_backend(db['ENGINE']) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 27, in load_backend return import_module('.base', backend_name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module import(name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 14, in from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/creation.py", line 1, in import psycopg2.extensions File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/init.py", line 50, in from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: @loader_path/../lib/libssl.1.0.0.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so Reason: image not found

Jonas Bolin
  • 606
  • 1
  • 11
  • 28

5 Answers5

11

This worked for me.

brew unlink openssl && brew link openssl --force

This will recreate correctly all the links to libssl 1.0 which was already installed.

poiuytrez
  • 21,330
  • 35
  • 113
  • 172
  • didn't fix it for me. :( – szeitlin Jun 30 '15 at 22:21
  • It worked for me under Mac OS X El Capitan, thanks! Django was looking for openssl-1.0.0 but now it uses openssl-1.0.2d_1 (I did a `brew uninstall openssl` and `brew install openssl` before that) – Q Caron Oct 12 '15 at 09:07
  • Thanks this fixed my problem on El Capitan. Why does this work? – oLas May 12 '16 at 13:35
  • 2
    This no longer works with recent Homebrew, instead you get `Warning: Refusing to link: openssl`. Instead use `CFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip ...` – Danielle Madeley Nov 29 '16 at 04:06
  • 1
    @DanielleMadeley Can you please provide the complete solution ? Seems like there's more to that command. – coding_idiot Oct 11 '17 at 19:26
3

psycopg2 is missing. Postgresql database adapter for Python.

You need to reinstall Postgresql. You're on a mac, so install it using brew.

brew install postgresql

If brew outputs that it's already installed, uninstall it and reinstall it again.

  • 1
    I had installed the postgres.app (www.postgresapp.com) and I uninstalled that one and reinstalled via Homebrew, to no avail. Same error. – Jonas Bolin Nov 04 '13 at 13:25
  • 6
    what if you define the environment variable like this: `export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.*/lib` replace 9.* with the postgresql current version –  Nov 04 '13 at 13:31
  • Yay, defining the environment variable works! Thanks a lot, struggling for hours with this. – Jonas Bolin Nov 04 '13 at 14:02
2

It seems that it's libssl.1.0.0.dylib that is missing. Mavericks comme with libssl 0.9.8. You need to install libssl via homebrew.

If loaderpath points to /usr/lib/, you also need to symlink libssl from /usr/local/Cell/openssl/lib/ into /usr/lib.

  • For a more general answer (not _Homebrew_ specific) see [this SO question about Python and PostgreSQL](http://stackoverflow.com/questions/11538249/python-pip-install-psycopg2-install-error) – ᴠɪɴᴄᴇɴᴛ Apr 21 '14 at 22:45
1

This problem happened to me because I was using posqgressapp. This is probably related to sandboxing.

Delete the posqgressapp and install postgress using brew solved my problem.

Install Postgress using HomeBrew:
http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/

Unable to open psql on Mavericks:
https://github.com/PostgresApp/PostgresApp/issues/137

1

Installing the full PostgreSQL server on my OSX laptop bothers me. Uninstall is clunky and now you have a pretty rocking DB server just sitting unused just for the libraries.

I know others have posted against using Postgres.app but I love it. Its clean and easy to use. The key is to remember that its just a folder with all the necessary libraries inside to help when building Psycopg2 on your OSX box. Just make sure add something to your path so you can find the libraries like:

$ PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/

(Alter, of course based upon the version of Postgres.app that you installed.)

Once you get your psycopg2 compiled you simply drag Postgres.app to the trash and its gone. Easy peasy.

I wasted a lot of time with all kind of errors and psycopg2 on both OSX & Linux, so I threw this together:

http://www.codychamberlain.com/posts/installing-psycopg2-on-osx/