Reputation: 1432
I've looked at every post concerning this issue. I've (re)installed PostgreSQL on my Mac using Homebrew. I've adjusted the PATH variables. I've installed/uninstalled/reinstalled psycopg2. I've watched videos. Still, I cannot figure out how psycopg2 can be squarely on my machine and yet unavailable to my database and, by extension, my Flask application. Here is my latest error message with confirmation that, yes, it's there and, no, I can't use it (or Python won't acknowledge it). Any help would be greatly appreciated. This is day two of this nonsense.
RCD@Ryans-MacBook-Pro ~ - $ sudo pip3 install psycopg2
Password:
Requirement already satisfied: psycopg2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2.7.5)
RCD@Ryans-MacBook-Pro ~ - $ python
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: No module named _psycopg
Upvotes: 2
Views: 3984
Reputation: 94512
So you've installed psycopg2
into Python 3.7 but tried to use it in Python 2.7.
python
and pip
must be synchronized; the simplest way to do that is to run python -m pip
instead of pip
, that way you guarantee that you use correct pip
for your current python
.
Please remember that sudo
uses a different $PATH
so you'd better set the full path to your python
:
sudo /Library/Frameworks/Python.framework/Versions/2.7/bin/python -m pip install -U psycopg2-binary
Upvotes: 1