Magic not working. Please Help

I’m currently trying to run SQL in Jupyter Notebook but seem to be having an issue with the magic commands.

image

When I run my script in the integrated Jupyter Notebook environment on DataQuest I have no issues but as soon as I try to run it in my own bowser the “%” turns black and I get errors. I am getting the same problem when I try to run it from the Jupyter extension in VS Code.

Please help! Thank you!!

When you are reporting errors, please always make sure to report what those errors are, including any error messages and tracebacks.

Since you are describing two or three different environments, it seems likely that there is a difference of versions and packages available. For example, %load_ext sql assumes you have jupysql installed.

@minrk That fixed it though I am still not entirely sure what was wrong in the first place. A friend was able to run my code without jupysql. They had the following:

Package                   Version
------------------------- ---------------
anyio                     4.2.0
appnope                   0.1.3
argon2-cffi               23.1.0
argon2-cffi-bindings      21.2.0
arrow                     1.3.0
asttokens                 2.4.1
async-lru                 2.0.4
attrs                     23.2.0
Babel                     2.14.0
beautifulsoup4            4.12.3
bleach                    6.1.0
certifi                   2023.11.17
cffi                      1.16.0
charset-normalizer        3.3.2
comm                      0.2.1
debugpy                   1.8.0
decorator                 5.1.1
defusedxml                0.7.1
executing                 2.0.1
fastjsonschema            2.19.1
fqdn                      1.5.1
greenlet                  3.0.3
idna                      3.6
ipykernel                 6.29.0
ipython                   8.20.0
ipython-genutils          0.2.0
ipython-sql               0.5.0
ipywidgets                8.1.1
isoduration               20.11.0
jedi                      0.19.1
Jinja2                    3.1.3
json5                     0.9.14
jsonpointer               2.4
jsonschema                4.21.1
jsonschema-specifications 2023.12.1
jupyter                   1.0.0
jupyter_client            8.6.0
jupyter-console           6.6.3
jupyter_core              5.7.1
jupyter-events            0.9.0
jupyter-lsp               2.2.2
jupyter_server            2.12.5
jupyter_server_terminals  0.5.2
jupyterlab                4.0.11
jupyterlab_pygments       0.3.0
jupyterlab_server         2.25.2
jupyterlab-widgets        3.0.9
MarkupSafe                2.1.4
matplotlib-inline         0.1.6
mistune                   3.0.2
nbclient                  0.9.0
nbconvert                 7.14.2
nbformat                  5.9.2
nest-asyncio              1.6.0
notebook                  7.0.7
notebook_shim             0.2.3
numpy                     1.26.3
overrides                 7.7.0
packaging                 23.2
pandas                    2.2.0
pandocfilters             1.5.1
parso                     0.8.3
pexpect                   4.9.0
pip                       23.3.2
platformdirs              4.1.0
prettytable               3.9.0
prometheus-client         0.19.0
prompt-toolkit            3.0.43
psutil                    5.9.8
ptyprocess                0.7.0
pure-eval                 0.2.2
pycparser                 2.21
Pygments                  2.17.2
python-dateutil           2.8.2
python-json-logger        2.0.7
pytz                      2023.3.post1
PyYAML                    6.0.1
pyzmq                     25.1.2
qtconsole                 5.5.1
QtPy                      2.4.1
referencing               0.32.1
requests                  2.31.0
rfc3339-validator         0.1.4
rfc3986-validator         0.1.1
rpds-py                   0.17.1
scipy                     1.12.0
Send2Trash                1.8.2
setuptools                67.6.1
six                       1.16.0
sniffio                   1.3.0
soupsieve                 2.5
SQLAlchemy                2.0.25
sqlparse                  0.4.4
stack-data                0.6.3
terminado                 0.18.0
tinycss2                  1.2.1
tornado                   6.4
traitlets                 5.14.1
types-python-dateutil     2.8.19.20240106
typing_extensions         4.9.0
tzdata                    2023.4
uri-template              1.3.0
urllib3                   2.1.0
wcwidth                   0.2.13
webcolors                 1.13
webencodings              0.5.1
websocket-client          1.7.0
widgetsnbextension        4.0.9

The error I was getting was:

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([])

and

Environment variable $DATABASE_URL not set, and no connect string given.
Connection info needed in SQLAlchemy format, example:
               postgresql://username:password@hostname/dbname
               or an existing connection: dict_keys([])

I made a post on StackOverflow that provides some more detail and screenshots:

Thanks for the help!

jupysql is a fork of ipython-sql, which they have. It’s an older version of the same thing.

1 Like