[Python] how to connect to sqlite from sqlalchemy

Discussão em 'Python' iniciado por Stack, Fevereiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I have a sqlite db in my home dir.

    stephen@stephen-AO725:~$ pwd
    /home/stephen
    stephen@stephen-AO725:~$ sqlite db1
    SQLite version 2.8.17
    Enter ".help" for instructions
    sqlite> select * from test
    ...> ;
    3|4
    5|6
    sqlite> .quit


    when I try to connect from a jupyter notebook with sqlalchemy and pandas, sth does not work.

    db=sqla.create_engine('sqlite:////home/stephen/db1')
    pd.read_sql('select * from db1.test',db)


    ~/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/default.py in do_execute(self, cursor, statement, parameters, context)
    578
    579 def do_execute(self, cursor, statement, parameters, context=None):
    --> 580 cursor.execute(statement, parameters)
    581
    582 def do_execute_no_params(self, cursor, statement, context=None):

    DatabaseError: (sqlite3.DatabaseError) file is not a database
    [SQL: select * from db1.test]
    (Background on this error at: http://sqlalche.me/e/4xp6)


    I also tried:

    db=sqla.create_engine('sqlite:///~/db1')


    same result

    Continue reading...

Compartilhe esta Página