I was creating a very basic python program connecting it with database in psql.
My code is as following:
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
engine=create_engine("postgresql+psycopg2://sidrules:password@localhost:5432/first")
db=scoped_session(sessionmaker(bind=engine))
def main():
flights=db.execute("select origin, destination, duration from flights").fetchall()
for flight in flights:
print(f"from {flight.origin} to {flight.destination} in {flight.duration} min")
if name == "main":
main()
while running the above code I am getting following error (Sorry for strange formatting):
*Traceback (most recent call last): File "select.py", line 6, in engine=create_engine("postgres+psycopg2://sidrules:secret@localhost:5432/first") File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\engine__init__.py", line 479, in create_engine return strategy.create(*args, **kwargs) File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\engine\strategies.py", line 61, in create entrypoint = u._get_entrypoint() File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\engine\url.py", line 172, in _get_entrypoint cls = registry.load(name) File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\util\langhelpers.py", line 253, in load loader = self.auto_fn(name) File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\dialects__init__.py", line 45, in _auto_fn module = import("sqlalchemy.dialects.%s" % (dialect,)).dialects File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\dialects\postgresql__init__.py", line 8, in from . import base File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\dialects\postgresql\base.py", line 954, in from uuid import UUID as _python_UUID # noqa File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\uuid.py", line 57, in _AIX = platform.system() == 'AIX' File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\platform.py", line 891, in system return uname().system File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\platform.py", line 779, in uname node = _node() File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\platform.py", line 582, in _node import socket File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 52, in import os, sys, io, selectors File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\selectors.py", line 12, in import select File "D:\HTML\SQL\select.py", line 6, in engine=create_engine("postgres+psycopg2://sidrules:sidhhant@localhost:5432/first") File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\engine__init__.py", line 479, in create_engine return strategy.create(*args, **kwargs) File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\engine\strategies.py", line 61, in create entrypoint = u._get_entrypoint() File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\engine\url.py", line 172, in _get_entrypoint cls = registry.load(name) File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\util\langhelpers.py", line 253, in load loader = self.auto_fn(name) File "C:\Users\Home\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\dialects__init__.py", line 49, in _auto_fn
module = getattr(module, dialect)
AttributeError: module 'sqlalchemy.dialects' has no attribute 'postgresql'*
of which I think the last line has to worry about:
AttributeError: module 'sqlalchemy.dialects' has no attribute 'postgresql'
Thank you, for your help.
Sorry, for strange format, it's my first question.
Thankyou, to everyone who had seen and thought about my question.
The only problem I had is that the name of my file was 'select.py'. I don't know how but renaming the file did the trick for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With