Error: no module named psycopg2.extensions

I am trying to set up a PostgreSQL database for my django project, which I believe has now done thanks to the answers to my last question Problems setting up a postgreSQL database for a django project . Now I am trying to run the command “python manage.py runningerver” in Terminal to get my local host, but when I run the command, I see this answer ...

Error: No module named psycopg2.extensions 

I'm not sure what this means - I tried to download psycopg2, but cannot find a way to download psycopg2 using homebrew. I tried easy_install, pip install and sudo, but all returning 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 it?

+57
python django postgresql psycopg2
04 Oct
source share
14 answers

The first thing to do is install the dependencies.

 sudo apt-get build-dep python-psycopg2 

After that, go into your virtualenv and use

 pip install psycopg2-binary 

These two teams should solve the problem.

+127
Jan 13 '13 at 22:28
source share
 pip install psycopg2-binary 

The psycopg2 wheel package will be renamed from version 2.8; to continue the installation from the binary, use "pip install psycopg2-binary" instead. For more information, see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi .

+6
Mar 15 '18 at 20:34
source share

install apt-get install python-setuptools

then try easy_install psycopg2

+5
04 Oct
source share

This is what helped me on Ubuntu if your python is installed from an Ubuntu installer. I did this after an unsuccessful attempt to "apt-get install" and "pip install":

In terminal:

 sudo synaptic 

then in the synaptic search box write

 psycopg2 

select

 python-psycopg2 

mark it for installation with the right mouse button and click "apply". Of course, if you did not install synaptic, first run:

 sudo apt-get install synaptic 
+4
Apr 04 '13 at 21:32
source share

I have successfully installed these commands:

 sudo apt-get install libpq-dev python-dev pip install psycopg2 
+4
Jun 09 '16 at 5:05
source share

In Python 3.4, while in a virtual environment, first make sure you have build dependencies:

 sudo apt-get build-dep python3-psycopg2 

Then install it:

 pip install psycopg2 
+3
Jun 12 '16 at 22:15
source share

For Django 2 and python 3 install psycopg2 using pip3 :

 pip3 install psycopg2 
+2
Jan 04 '18 at 15:34
source share

It seems you need gcc-4.0 , and it would be useful to specify the type and version of your OS.

Perhaps this question will help you a bit: Installing GCC on Mac OS X Leopard without installing Xcode

Update

I am a Windows user, so I can’t verify your setup, but a quick Google pointed out some more links:

+1
04 Oct
source share

I encountered a No module named psycopg2.extensions when trying to run pip2 install psycopg2 on a Mac with Macvericks (10.9). I don't think my stack trace included a gcc message, but also included a hint:

 Error: pg_config executable not found. Please add the directory containing pg_config to the PATH or specify the full executable path with the option: python setup.py build_ext --pg-config /path/to/pg_config build ... or with the pg_config option in 'setup.cfg'. 

I searched the pg_config file in my Postgres installation and added the folder containing it to my path: /Applications/Postgres.app/Contents/Versions/9.4/bin . Your path may be different, especially if you have a different version of Postgres installed - I will just poke until you find the bin/ folder. After that, the installation worked.

+1
Jun 15 '16 at 13:41
source share

try the following:
sudo pip install -i https://testpypi.python.org/pypi psycopg2 == 2.7b2 <w> .. this is especially useful if you encounter an egg error

in aws ec2 instances if you encounter a gcc error; try this 1. sudo yum install gcc python-setuptools python-devel postgresql-devel
2.sudo su -
3.sudo pip install psycopg2

+1
Feb 24 '17 at 23:33
source share

I used the extension after importing psycopg2:

 import psycopg2 ... psycopg2.extensions.AsIs(anap[i]) 
0
04 Oct '12 at 13:18
source share

you can install gcc for macos from https://github.com/kennethreitz/osx-gcc-installer
after installing gcc, you can install psycopg using easy_install or using pip

0
04 Oct
source share

Make sure you install psycopg2, if not

 sudo apt-get install psycopg2 

Install the dependencies.

 sudo apt-get build-dep python-psycopg2 

These two teams should solve the problem.

0
Mar 12 '13 at 6:25
source share

On Alpine Linux (most dock containers) do:

 apk add postgresql-dev 

Then:

 pip install psycopg2-binary 
0
Dec 25 '18 at 13:41
source share



All Articles