1

I'm trying to work with psycopg2 natively on Mac. It installs fine, with no errors at least, but when i import it get an error message.

I've seen dozens of threads with similar issues and solutions that vary massively and just seem excessive for such a common module.

can anyone help?

Last login: Wed Oct 12 15:47:24 on console
Gurmokhs-MBP:~ Gurmokh$ pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in     /Library/Python/2.7/site-packages
Gurmokhs-MBP:~ Gurmokh$ python
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 12:54:16) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] 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/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/psycopg2-2.6.2-py2.7-macosx-10.6-intel.egg/psycopg2/__init__.py",     line 50, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME,    ROWID
ImportError:     dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site    -packages/psycopg2-2.6.2-py2.7-macosx-10.6-    intel.egg/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from:     /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/psycopg2-2.6.2-py2.7-macosx-10.6-intel.egg/psycopg2/_psycopg.so
  Reason: image not found
>>> ^D
Gurmokhs-MBP:~ Gurmokh$ 

I can see some copies floating round from different applications. I'm assuming i could copy one of these. The above message tells me what is referencing this file, but they do not tell me where they expect to find it. If i knew where it should go i would try this.

bash-3.2# find . -name "libssl.1.0.0.dylib"
./Library/Application Support/Fitbit Connect/libssl.1.0.0.dylib
./Library/PostgreSQL/9.5/lib/libssl.1.0.0.dylib
./Library/PostgreSQL/9.5/pgAdmin3.app/Contents/Frameworks/libssl.1.0.0.dylib
./Users/Gurmokh/.Trash/Navicat for PostgreSQL.app/Contents/Frameworks/libssl.1.0.0.dylib
VynlJunkie
  • 1,338
  • 16
  • 21
  • Could you discuss a bit what you've tried? Effectively you need to place libssl.1.0.0.dylib somewhere it can be found. – jimjkelly Oct 12 '16 at 16:39
  • edited to show some attempt at understanding the problem and what i've done. – VynlJunkie Oct 12 '16 at 23:00
  • Feels like i'm stabbing in the dark. Ive tried methods from here http://stackoverflow.com/questions/27264574/import-psycopg2-library-not-loaded-libssl-1-0-0-dylib/30726895#30726895 and here http://mithun.co/hacks/library-not-loaded-libcrypto-1-0-0-dylib-issue-in-mac/ nothing seems to work. Its driving me nuts. – VynlJunkie Oct 12 '16 at 23:32
  • 1
    Try another distribution of Python, eg. Anaconda; in my experience it's generally a bad idea to rely on the distro of Python that comes with Mac OS. – maxymoo Oct 13 '16 at 01:10
  • if you really want to use the system distro looks like you'll have to understand frameworks http://stackoverflow.com/questions/17759740/python-under-mac-os-x-framework looks like a headache tho – maxymoo Oct 13 '16 at 01:13
  • 1
    Did you set the DYLD_FALLBACK_LIBRARY_PATH to `./Library/PostgreSQL/9.5/lib` or just paste in the Anaconda links? I'd second @maxymoo's comment on not using the built-in Python - but you don't necessarily need Anaconda, you can install Python from python.org. Or, honestly use something like Docker - all these sorts of headaches go away. Though you have to learn a new tool then, but it's worth it in my opinion... – jimjkelly Oct 13 '16 at 12:10

1 Answers1

1

Thanks guys.

@maxymoo I went with your suggestion. I have installed anaconda2. The install updated my path to include /anaconda/bin.

Then using the navigator I installed pyscopg2. Now I am able to use this in the shebang and my scripts execute fine and i'm able to import this module.

Gurmokhs-MBP:rest Gurmokh$ python
Python 2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul  2 2016, 17:43:17) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import psycopg2
if psycopg2.connect("dbname='postgres' user='postgres' host='localhost'"):
...     print "connection made"
... 
connection made
>>> 
VynlJunkie
  • 1,338
  • 16
  • 21
  • 1
    some modules are not present that i would have expected urllib, oauth. I have had to install them using conda install. Instructions found on anaconda cloud website. – VynlJunkie Oct 14 '16 at 11:06