Reputation: 99
I've already installed the dependencies with sudo apt-get build-dep python-psycopg2
and then installing psycopg2
with sudo pip install psycopg2
and even with easy_install psycopg2
. But even after all this, if I run python3 code.py
I get
ImportError: No module named 'psycopg2'
If I run sudo apt-get build-dep python3-psycopg2
I get
Picking 'psycopg2' as source package instead of 'python3-psycopg2'
0 upgraded, 0 newly installed, 0 to remove and 144 not upgraded.
Same with sudo apt-get build-dep python-psycopg2
Please help.
Upvotes: 4
Views: 27452
Reputation: 86
In my case, pip3 install psycopg2
made psycopg3 available for python3, while I was trying to execute my code in python 2.7 by default
so changing my call from
python foo.py
to python3 foo.py
helped
Upvotes: 0
Reputation: 159
I faced the same issue. I tried 'sudo apt-get build-dep python-psycopg2' It didn't work. I was trying to connect to a postgres database. It turns out that I didn't have postgresql installed. Once I installed it, the error went away.
Upvotes: 0
Reputation: 665
If you are using the Anaconda distribution, make sure to go with:
conda install -c anaconda psycopg2=2.6.2
https://anaconda.org/anaconda/psycopg2
Upvotes: 1
Reputation: 34
try:
# debian like
$ sudo apt-get install python3-dev
$ pip3 install psycopg2
# check installation
$ python3
import psycopg2
Upvotes: 0
Reputation: 1476
its always better to work in virtualenv and not mess up with your system
try:
virtualenv -p /usr/bin/python3 test_env
source test_env/bin/activate
pip install psycopg2
run python and try to import
if you insist on installing it on your systems python try:
pip3 install psycopg2
Upvotes: 6