Reputation: 61
I'm using Mac os.
I installed pyscopg2 successfully (pip3 install psycopg2
)
But when I try to import psycopg2 I get the following message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'psycopg2'
Upvotes: 6
Views: 9652
Reputation: 653
You can install 'psycopg2==2.7.5' using this command:
pip install psycopg2==2.7.5
psycopg2 2.7.5 is the last version that doesn't require building from source. Although it'll throw the following warning every time it is initialized in code:
UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
So you can alternatively use pip install psycopg2-binary
Upvotes: 7
Reputation: 598
Execute (For Python 2)
sudo apt-get install build-dep python-psycopg2
pip install psycopg2
For Python 3
sudo apt-get install build-dep python-psycopg3
pip install psycopg3
Upvotes: 0
Reputation: 2978
First Install psycopg2 on both the python version, only if you don't which one you are targetting.
Command - pip install psycopg2 (for python 3) Command - pip3 install psycopg2 (for python 2)
Although, if it does not work there is one more way as well using the .whl(wheel file)
using the wheel - pip install and from here you can download .whl file
pip install your.whl
Download the wheel file taking the version of your python in mind.
Hope it helps.
Upvotes: 0