Problems with Psycopg2 on MAC

2

I'm catching up with Python + Postgre and Psycopg2.

I installed Python 3.4 on my MAC, then Postgre, and then followed the following steps:

export PATH=/Library/PostgreSQL/9.4/bin:$PATH
pip install psycopg2

He installed Psycopg 2, but when I give an import I get the following error:

/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /Users/leandro/PycharmProjects/Teste/teste.py
Traceback (most recent call last):
  File "/Users/leandro/PycharmProjects/Teste/teste.py", line 1, in <module>
    import psycopg2
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/__init__.py", line 50, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so
  Reason: image not found

Process finished with exit code 1

On the web I found references to do the following:

sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old 
sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib

or

sudo ln -s /Library/PostgreSQL/9.4/lib/libpq.5.dylib /usr/lib

But did not solve ... Any tips?

    
asked by anonymous 04.07.2015 / 16:42

1 answer

0

I do not work with Psycopg2 so my answer is more general, which can help with this kind of problem.

Since you are adding something to PATH before installing, it is possible that the same modification is required permanently, or at least always before running any program that will use that component.

A simple alternative is to create or modify your .bashrc file (in /Users/leandro/.bashrc ) by adding that same line:

export PATH=/Library/PostgreSQL/9.4/bin:$PATH

Open a new Terminal tab or window.

If you have replaced the default Python of your Mac with 3.4, I would suggest running pip with sudo :

sudo pip install psycopg2

If you are instead using virtualenv , remember to enable it before installing:

cd ~/PycharmProjects/Teste
source nome-do-env/bin/activate
pip install psycopg2

I imagine that now you can run your program in the same Terminal:

sudo python ~/PycharmProjects/Teste/teste.py

Another option . Since you seem to be using PyCharm , take a look at the runtime settings: menu Run > Edit configurations... . Find the configuration you are using to run your program, edit the Environment variables field by adding a new value: Name = PATH , Value = /Library/PostgreSQL/9.4/bin:$PATH . So, whenever PyCharm is running your program, the value of PATH will be the same modified value that you used to install Psycopg2 .     

07.07.2015 / 18:19