Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psycopg2: AttributeError: 'module' object has no attribute 'extras'

In my code I use the DictCursor from psycopg2.extras like this

dict_cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)

However, all of the sudden I get the following error when I load the cursor:

AttributeError: 'module' object has no attribute 'extras'

Maybe something is dorked in my installation but I have no clue where to start looking. I made some updates with pip, but as far as I know no dependencies of psycopg2.

like image 405
n1000 Avatar asked Jun 19 '15 14:06

n1000


2 Answers

You need to explicitly import psycopg2.extras:

import psycopg2.extras
like image 135
Uyghur Lives Matter Avatar answered Oct 21 '22 14:10

Uyghur Lives Matter


As of July 2018, the import psycopg2.extras doesn't work for me. The following works for me:

pip install psycopg2-binary

and later:

>>> import psycopg2.errorcodes
>>> psycopg2.errorcodes.UNIQUE_VIOLATION
'23505'
like image 26
Bartłomiej Szałach Avatar answered Oct 21 '22 15:10

Bartłomiej Szałach