Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'psycopg2'

Tags:

python

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.

like image 282
user2316393 Avatar asked Sep 02 '25 08:09

user2316393


1 Answers

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
like image 61
Urban48 Avatar answered Sep 04 '25 21:09

Urban48