MetaData.__init__() got an unexpected keyword argument 'bind' when using sqlite
Asked Answered
B

4

7

im very new to sqlite, im using macbook m1, im try to use jupyter notebook to do sql here is my code

%load_ext sql

import csv, sqlite3

con = sqlite3.connect("socioeconomic.db")
cur = con.cursor()

everything is okay until this but when i connect to the sqlite

%sql sqlite:///socioeconomic.db

there is error something like this

MetaData.__init__() got an unexpected keyword argument 'bind'
Connection info needed in SQLAlchemy format, example:
               postgresql://username:password@hostname/dbname
               or an existing connection: dict_keys([])

do you have any suggestion what should i do?

i tried to use other laptop but windows, and the same code works, but in mac isnt

Balboa answered 1/4, 2023 at 21:7 Comment(0)
E
4

Check out this guide! Essentially there are 2 ways you can connect from your Jupyter notebook to SQLite local db. I don't think it relates to your Mac version as I have M2 and it's running fine.

Check you have the .db file locally. Also, check if the same sqlalchemy versions are matching. I believe pip install sqlalchemy==1.4.4 should work. Another reason to move to Jupysql is that it supports the latest SQLAlchemy version.

Here are 2 ways you can make it run via Jupysql:

  1. You can pass your existing connections to %sql as follows:
some_engine = create_engine("sqlite:///some.db")
%sql some_engine
  1. You can connect directly to it:
%sql sqlite:///foo.db

For both options you'll need to set up the correct package and import it via %load_ext sql

Endurable answered 10/4, 2023 at 18:22 Comment(3)
wow big thanks, after i tried to install install jupysql duckdb-engine it works somehowBalboa
That's awesome, feel free to accept the answer :) You can also join our community, we'd love to hear your use case! ploomber.io/communityEndurable
Confirmed using jupysql fixed the issue, it's the fork of iphyton-sql. Command to install on conda conda install jupysql -c conda-forge (from their docs)Pathless
B
0

What I did was to simply downgrade the SQLalchemy version. Mine was 2.0, so I rolled it back to version 1.4.39. To do this, head on to the environment tab, select and apply version 1.4.39. Make sure to restart the kernel.

Bah answered 6/11, 2023 at 14:25 Comment(0)
J
0

De-versioning worked for me. Sqlalchemy v2.0 --> v1.4.4

Junie answered 5/3 at 10:24 Comment(0)
M
0

The ability to bind engines or connections to metadata objects was removed in SQLAlchemy 2.0 (or 1.4 with future=True set on the engine). See “Implicit” and “Connectionless” execution, “bound metadata” removed. Instead, the engine of connection may be passed to methods that require it:

engine = create_engine(...)

metadata = MetaData()
metadata.drop_all(engine)
metadata.create_all(engine)
metadata.reflect(engine)

This and other breaking changes in 2.0 are documented in

Miniver answered 13/10 at 6:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.