Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: No module named psycopg2.extensions

I am trying to set up a PostgreSQL database for my django project, which I believe I have done now thanks to the replies to my last question Problems setting up a postgreSQL database for a django project. I am now trying to run the command 'python manage.py runserver' in Terminal to get my localhost up but when I run the command, I see this response...

Error: No module named psycopg2.extensions 

I'm not sure what this means - I have tried to download psycopg2 but can't seem to find a way to download psycopg2 using homebrew. I have tried easy_install, pip install and sudo but all return errors like this...

Downloading http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.5.tar.gz Processing psycopg2-2.4.5.tar.gz Writing /tmp/easy_install-l7Qi62/psycopg2-2.4.5/setup.cfg Running psycopg2-2.4.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-l7Qi62/psycopg2-2.4.5/egg-dist-tmp-PBP5Ds no previously-included directories found matching 'doc/src/_build' unable to execute gcc-4.0: No such file or directory error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1 

How to fix this?

like image 301
Jess Avatar asked Oct 04 '12 13:10

Jess


People also ask

How do you fix ModuleNotFoundError No module named psycopg2?

The Python "ModuleNotFoundError: No module named 'psycopg2'" occurs when we forget to install the psycopg2-binary module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install psycopg2-binary command.

How do I install psycopg2 on Windows 10?

Install the psycopg2 module in Windows 10 Now that we have our virtual environment setup and ready, install the psycopg2 module to create a simple connection in the PostgreSQL database cluster. Make sure to upgrade the pip command to avoid error when installing a package module from python in a virtual environment.

What is psycopg2 module in Python?

Psycopg is the most popular PostgreSQL database adapter for the Python programming language. Its main features are the complete implementation of the Python DB API 2.0 specification and the thread safety (several threads can share the same connection).


1 Answers

The first thing to do is to install the dependencies.

sudo apt-get build-dep python-psycopg2 sudo apt install python3-psycopg2 # Python 3

After that go inside your virtualenv and use:

pip install psycopg2-binary 

These two commands should solve the problem.

like image 97
Fernando Munoz Avatar answered Oct 04 '22 19:10

Fernando Munoz