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

n1000 picture n1000 · Jun 19, 2015 · Viewed 25.6k times · Source

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.

Answer

All Workers Are Essential picture All Workers Are Essential · Jun 19, 2015

You need to explicitly import psycopg2.extras:

import psycopg2.extras