0
import os

from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

engine = create_engine("postgresql://postgres:114920@localhost/Databases")
db = scoped_session(sessionmaker(bind=engine))

def main():
    Railway = db.execute("SELECT origin, destination, duration FROM Railway").fetchall()
    for railway in Railway:
        print(f"{railway.origin} to {railway.destination}, {railway.duration} minutes")

if __name__ == "__main__":
    main()

and got this error (if possible pls share code I'm stuck at this foe a long time)

C:\Web Development\Lecture02>python hoja1.py Traceback (most recent call last): File "C:\Web Development\Lecture02\hoja1.py", line 6, in engine = create_engine("postgresql://postgres:114920@localhost/Databases") File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine_init_.py", line 500, in create_engine return strategy.create(*args, **kwargs) File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\strategies.py", line 87, in create dbapi = dialect_cls.dbapi(**dbapi_args) File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\dialects\postgresql\psycopg2.py", line 778, in dbapi import psycopg2 ModuleNotFoundError: No module named 'psycopg2'

1
  • 1
    Hi, you are missing psycopg2 module which is sqlalchemy using for interacting with postgresql. Do you have it installed? pip install psycopg2 Commented Dec 15, 2020 at 10:22

2 Answers 2

0

looks like you dont have psycopg2 module try pip installing psycopg2 run this command in your terminal

pip install psycopg2
Sign up to request clarification or add additional context in comments.

Comments

0
import os

from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker

engine = create_engine("postgresql://postgres:114920@localhost:5432/postgres") db = scoped_session(sessionmaker(bind=engine))

def main(): Railway = db.execute("SELECT origin, destination, duration FROM Railway").fetchall() for railway in Railway: print(f"{railway.origin} to {railway.destination}, {railway.duration} minutes")

if name == "main": main()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.