'psycopg2.extensions.connection' object has no attribute 'get_dsn_parameters'

I've just upgraded postgresql-client from 9.1 to 9.5 on Ubuntu 16.04. (I plan to upgrade everything further, but I want to get this working first.) I have also upgraded from psycopg2 2.6.1 to psycopg2 2.8.6, but when I try to execute

print(conn.get_dsn_parameters())

I still get the error message

'psycopg2.extensions.connection' object has no attribute 'get_dsn_parameters'

even though the psycopg2 docs say get_dsn_parameters requires libpq >= 9.3. From this I infer psycopg2 has linked against libpq 9.1; would this be correct? How do I get psycopg2 working with the correct version of libpq?

Thanks.