Psycopg2 on Mac OS X (Snow Leopard)

561 views
Skip to first unread message

Skip Montanaro

unread,
Oct 27, 2013, 10:20:40 AM10/27/13
to django...@googlegroups.com
I'm working my way through my first non-tutorial Django project. I
plan to deploy it (at least initially) on Heroku. I'm at the point
where I have my basic structure laid out and am proceeding to model
definition. Heroku's default database is PostgreSQL, which I'm
comfortable with, and seems to be installed properly there. The
locally built psycopg2 module (2.5.1) is missing libssl, however:

(venv)topten% python manage.py shell
ImportError: dlopen(/Users/skip/heroku/topten/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so,
2): Library not loaded: libssl.1.0.0.dylib
Referenced from:
/Users/skip/heroku/topten/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found

Looking on my Mac running Snow Leopard (10.6.8), I only see 0.9.x
versions of libssl in /usr/lib. I have no libssl in my MacPorts
directory (/opt/local/lib).

Where did whatever built psycopg2 (pip?) get the idea that I had
libssl 1.0? More importantly, how can I get past this bump in the
road?

Thanks,

Skip Montanaro

Doug Snyder

unread,
Oct 27, 2013, 10:46:22 AM10/27/13
to django...@googlegroups.com
I don't have a very specific answer for your question. I just started doing my django dev on OSX coming from Ubuntu
My understanding is that Home Brew is a better solution than Mac Ports, I have heard some people being very critical of Mac Ports which I think was once the best solution for python environments on OSX but I think has been mostly replaced by Home Brew. Switching over may solve your problem automatically and may make life easier down the road too. But maybe someone else will have a more knowledgable, specific answer to your specific problem.
Another solution that doesn't require and headaches is that Mavericks, the new OSX release may still be free for download. They announced it was free but the way they worded it made it sound like it may have only been free for the day it came out. Not sure if that's a road you want to go down or not.
Good Luck,
Doug



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANc-5UwY67Yh%3DoJJO%3D2TjOighTOK8xiviQz4oei3NS4oEVdK%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Skip Montanaro

unread,
Oct 27, 2013, 5:12:33 PM10/27/13
to django...@googlegroups.com
Thanks for the response. I only mentioned MacPorts to demonstrate that when psycopg2 was built, pip couldn't have found libssl 1.x there. I routinely build my own Python instances. The venv version of Python is a 2.7.5+ version built from hg.

Skip

Tom Lockhart

unread,
Oct 28, 2013, 9:39:27 AM10/28/13
to django...@googlegroups.com

On 2013-10-27, at 7:46 AM, Doug Snyder <webco...@gmail.com> wrote:

> I don't have a very specific answer for your question. I just started doing my django dev on OSX coming from Ubuntu
> My understanding is that Home Brew is a better solution than Mac Ports, I have heard some people being very critical of Mac Ports which I think was once the best solution for python environments on OSX but I think has been mostly replaced by Home Brew. Switching over may solve your problem automatically and may make life easier down the road too. But maybe someone else will have a more knowledgable, specific answer to your specific problem.

I can't address any benefits of switching. But I have been using MacPorts for some time and have had no problems.

Not sure who "some people" are wrt MacPorts but I haven't noticed complaints or problems (or in fact, any discussion of MacPorts vs Homebrew) in the context of Django or Postgres on the mailing list. I'm pretty sure both do this job just fine.

hth

- Tom


Adam Portier

unread,
Oct 28, 2013, 3:13:43 PM10/28/13
to django...@googlegroups.com
Good afternoon,

I just had this exact same problem and it took me a while to find the solution.

On OSx there is a separate library path variable for .dylib library files. I added the following to my .bashrc (or.bash_env or however you set up your shell environment).

export DYLD_LIBRARY_PATH="/usr/local/Cellar/openssl/1.0.1e/lib/:$DYLD_LIBRARY_PATH"

The folder "/usr/local/Cellar/openssl/1.0.1e/lib/" contains the libssl.1.0.0.dylib file that Python is trying to load. You will need to find where your copy is installed (find / -name libssl.1.0.0.dylib) and adjust your environment variable setting accordingly. After that I was able to run my Django server with no problems.

Skip Montanaro

unread,
Oct 28, 2013, 3:54:05 PM10/28/13
to django-users
> I just had this exact same problem and it took me a while to find the
> solution.
>
> On OSx there is a separate library path variable for .dylib library files. I
> added the following to my .bashrc (or.bash_env or however you set up your
> shell environment).
>
> export
> DYLD_LIBRARY_PATH="/usr/local/Cellar/openssl/1.0.1e/lib/:$DYLD_LIBRARY_PATH"

Thanks for the suggestion. Found libssl in the PostgreSQL installation:

% find / -name libssl.1.0.0.dylib 2>/dev/null
/Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib
/Library/PostgreSQL/9.2/pgAdmin3.app/Contents/Frameworks/libssl.1.0.0.dylib

I guess that makes sense. I should be able to modify the activate
script and deactivate function to set/reset DYLD_LIBRARY_PATH
appropriately.

Skip

Matthias Fripp

unread,
Nov 10, 2013, 4:16:55 AM11/10/13
to django...@googlegroups.com
I had the same problem. I am trying to make this work on a multi-user machine. My two options seem to be

(1) Add this line to /etc/profile:

export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.3/lib

The disadvantage of this is that changing DYLD_LIBRARY_PATH doesn't seem to be a common technique on Macs, and I'm not sure whether this would run if python is being used by some specialized account (rather than a normal login account).

(2) Create symbolic links in /usr/lib :

sudo ln -s /Library/PostgreSQL/9.3/lib/libpq.5.dylib /usr/lib/libpq.5.dylib
sudo ln -s /Library/PostgreSQL/9.3/lib/libssl.1.0.0.dylib /usr/lib/libssl.1.0.0.dylib
sudo ln -s /Library/PostgreSQL/9.3/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.1.0.0.dylib
(It may also have been possible to place these symbolic links in /Library/Python/2.6/site-packages/psycopg2/ , next to _psycopg.so .)

The disadvantage of using these symbolic links is that it will be harder to maintain when I switch to a new version of PostgreSQL. It was also tedious to find the list of missing dylibs by trial and error (in retrospect, I could have used otools -l /Library/Python/2.6/site-packages/psycopg2/_psycopg.so to get a full list of the libraries needed for psycopg2).

I would still like to find the "normal" way to add the whole /Library/PostgreSQL/9.3/lib/ directory to the Mac's dynamic library search path, especially for a multi-user machine. Installing PostgreSQL via HomeBrew instead of EnterpriseDB might take care of this automatically?

Matthias

Tom Lockhart

unread,
Nov 10, 2013, 11:08:18 AM11/10/13
to django...@googlegroups.com
On 2013-11-10, at 1:16 AM, Matthias Fripp <mfr...@gmail.com> wrote:

I had the same problem. I am trying to make this work on a multi-user machine. My two options seem to be

Neither seem good. I install most required packages which are not handled by pip using MacPorts (Homebrew works fine too afaik).

This has several advantages, not the least of which is you can avoid the shenanigans happening for your options (1) and (2) below. But the biggest advantage for me is that it gives me control over the versioning for the packages I am using. If you want to revlock on a version of Postgres, you can do that. If you want to run a different version from what Apple is shipping, or want to get a security release right away, you can do that. And you don't have to go diving down into Apple's library structure to figure out where things live or what version you are actually running.

hth

                          - Tom


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/groups/opt_out.

Tom Lockhart


Reply all
Reply to author
Forward
0 new messages