<pre><code>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()
</code></pre>
<p>我犯了这个错误
(如果可能的话,请分享我被困在这个敌人很长时间的代码)</p>
<blockquote>
<p>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_<em>init</em>_.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'</p>
</blockquote>