AttributeError: 'module' object has no attribute 'connect' in the pgdb module using python

Question:

    import pgdb
    myConnection = pgdb.connect( host=hostname, user=username, password=password, database=database )
    doQuery( myConnection )
    myConnection.close()

I get the following error when i run the script.

>>> AttributeError: 'module' object has no attribute 'connect'. Please help me out
Asked By: sham sar

||

Answers:

The classname is Connection in the repo https://github.com/KehaoWu/pgdb/blob/master/pgdb/pgdb.py#L15

PYPY project pypi.org/project/pgdb

Answered By: Vikas Mulaje

It is like that you have installed the "wrong" pgdb module. Try this:

python3.9 -m pip uninstall pgdb
python3.9 -m pip   install PyGreSQL

"You may either choose to use the “classic” PyGreSQL interface provided by the pg module or else the newer DB-API 2.0 compliant interface provided by the pgdb module." per http://www.pygresql.org/contents/pgdb/introduction.html . It is confusing to have two different modules with the same name.

Answered By: puravidaso
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.