snowflakedb / snowflake-sqlalchemy

Snowflake SQLAlchemy
https://pypi.python.org/pypi/snowflake-sqlalchemy/
Apache License 2.0
235 stars 152 forks source link

SNOW-783113: Not able to connect from jupyter notebook #405

Closed idomic closed 8 months ago

idomic commented 1 year ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

Python 3.9.12 (main, Apr 5 2022, 01:52:34) [Clang 12.0.0 ]`

  1. What operating system and processor architecture are you using?

macOS-12.4-arm64-arm-64bit`

  1. What are the component versions in the environment (pip freeze)?

alembic==1.8.1 ansiwrap==0.8.4 anyio==3.6.2 appnope==0.1.3 argon2-cffi==21.3.0 argon2-cffi-bindings==21.2.0 asttokens==2.0.8 attrs==22.1.0 autoviml==0.1.710 Babel==2.10.3 backcall==0.2.0 backoff==1.11.1 beautifulsoup4==4.11.1 bing-image-urls==0.1.5 black==22.10.0 bleach==5.0.1 boto3==1.24.85 botocore==1.27.85 brotlipy==0.7.0 catboost==1.1.1 certifi==2022.9.14 cffi @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/croot-jgj0vmyy/cffi_1642701117808/work chardet==3.0.4 charset-normalizer @ file:///tmp/build/80754af9/charset-normalizer_1630003229654/work click==8.1.3 cloudpickle==2.2.0 colorama==0.4.6 conda==4.12.0 conda-content-trust @ file:///tmp/build/80754af9/conda-content-trust_1617045594566/work conda-package-handling @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abscroot-4sc96bd/conda-package-handling_1649105290173/work contourpy==1.0.5 cryptography @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_5871d1ea-0250-4cd7-ac89-4b1e60514f5daqk8t0ow/croots/recipe/cryptography_1652101128666/work cycler==0.11.0 databricks-cli==0.17.3 debuglater==1.4.4 debugpy==1.6.3 decorator==5.1.1 defusedxml==0.7.1 docker==6.0.0 docutils==0.19 duckdb==0.5.0 duckdb-engine==0.7.0 emoji==2.2.0 entrypoints==0.4 executing==1.1.1 fastjsonschema==2.16.2 flake8==6.0.0 flake8-black==0.3.6 Flask==2.2.2 fonttools==4.38.0 gitdb==4.0.9 GitPython==3.1.29 graphviz==0.20.1 gunicorn==20.1.0 h11==0.14.0 headerparser==0.4.0 htmlmin==0.1.12 httpcore==0.16.3 httpx==0.23.3 idna==2.10 ImageHash==4.3.1 imbalanced-ensemble==0.1.7 imbalanced-learn==0.10.1 importlib-metadata==5.0.0 invoke==1.7.1 ipykernel==6.16.2 ipynb==0.5.1 ipython==8.5.0 ipython-genutils==0.2.0 ipython-sql==0.5.0 ipywidgets==8.0.4 itsdangerous==2.1.2 jedi==0.18.1 Jinja2==3.1.2 jmespath==1.0.1 joblib==1.2.0 json5==0.9.10 jsonschema==4.16.0 jupysql==0.6.0 jupyter==1.0.0 jupyter-console==6.4.4 jupyter-server==1.21.0 jupyter_client==7.4.4 jupyter_core==4.11.2 jupyterlab==3.5.0 jupyterlab-pygments==0.2.2 jupyterlab-widgets==3.0.5 jupyterlab_server==2.16.1 jupytext==1.14.4 kiwisolver==1.4.4 llvmlite==0.39.1 logzero==1.7.0 lxml==4.9.2 Mako==1.2.3 markdown-it-py==2.1.0 MarkupSafe==2.1.1 matplotlib==3.6.2 matplotlib-inline==0.1.6 mccabe==0.7.0 mdit-py-plugins==0.3.3 mdurl==0.1.2 memory-profiler==0.60.0 mistune==2.0.4 mlflow==1.30.0 monotonic==1.6 moto==4.0.6 multimethod==1.9.1 mypy-extensions==0.4.3 nbclassic==0.4.5 nbclient==0.7.0 nbconvert==7.2.8 nbformat==5.7.0 nbqa==1.6.3 ndjson==0.3.1 nest-asyncio==1.5.6 networkx==2.8.8 nltk==3.8.1 notebook==6.5.1 notebook_shim==0.2.0 numba==0.56.4 numpy==1.23.4 oauthlib==3.2.2 packaging==21.3 pandas==1.5.3 pandas-profiling==3.6.1 pandocfilters==1.5.0 papermill==2.4.0 parso==0.8.3 pathspec==0.10.1 patsy==0.5.3 pexpect==4.8.0 phik==0.12.3 pickleshare==0.7.5 Pillow==9.2.0 pkgmt==0.2.5 platformdirs==2.5.2 ploomber-core==0.2.6 ploomber-engine==0.0.24 plotly==5.13.0 posthog==2.1.2 prettytable==0.7.2 prometheus-client==0.15.0 prometheus-flask-exporter==0.20.3 prompt-toolkit==3.0.31 protobuf==4.21.8 psutil==5.9.3 psycopg2-binary==2.9.5 ptyprocess==0.7.0 pure-eval==0.2.2 pyarrow==10.0.1 pycodestyle==2.10.0 pycosat==0.6.3 pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work pydantic==1.10.2 pyflakes==3.0.1 Pygments==2.14.0 PyJWT==2.6.0 pylance==0.2.7 pyOpenSSL @ file:///opt/conda/conda-bld/pyopenssl_1643788558760/work pyparsing==3.0.9 pyrsistent==0.18.1 PySocks @ file:///Users/ktietz/Code/oss/ci_pkgs/pysocks_1626781349491/work python-dateutil==2.8.2 pytz==2022.4 PyWavelets==1.4.1 PyYAML==6.0 pyzmq==24.0.1 qtconsole==5.4.0 QtPy==2.3.0 querystring-parser==1.2.4 readme-renderer==24.0 regex==2022.10.31 requests==2.24.0 responses==0.21.0 rfc3986==1.5.0 rich==13.3.1 ruamel-yaml-conda @ file:///Users/ktietz/demo/mc3/conda-bld/ruamel_yaml_1629464769899/work s3transfer==0.6.0 scikit-learn==1.2.0 scipy==1.9.3 seaborn==0.12.1 Send2Trash==1.8.0 shap==0.41.0 six @ file:///tmp/build/80754af9/six_1644875935023/work sklearn-evaluation==0.8.4 slicer==0.0.7 smmap==5.0.0 sniffio==1.3.0 soupsieve==2.3.2.post1 SQLAlchemy==1.4.46 sqlparse==0.4.3 stack-data==0.5.1 statsmodels==0.13.5 svglue==0.3.0 tabulate==0.9.0 tangled-up-in-unicode==0.2.0 tenacity==8.1.0 terminado==0.17.0 testpath==0.6.0 textblob==0.17.1 textwrap3==0.9.2 threadpoolctl==3.1.0 tinycss2==1.2.1 tokenize-rt==5.0.0 toml==0.10.2 tomli==2.0.1 tornado==6.2 tqdm @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_d8374dd1-2388-4771-b0ef-a205a18076f0p40h0nwh/croots/recipe/tqdm_1650891080348/work traitlets==5.5.0 typeguard==2.13.3 typing_extensions==4.4.0 urllib3==1.25.11 vaderSentiment==3.3.2 visions==0.7.5 wcwidth==0.2.5 webencodings==0.5.1 websocket-client==1.4.1 Werkzeug==2.2.2 wget==3.2 wheel-filename==1.4.1 wheel-inspect==1.6.0 widgetsnbextension==4.0.5 xgboost==1.7.3 xlrd==2.0.1 xmltodict==0.13.0 yapf==0.32.0 yellowbrick==1.5 zipp==3.10.0

  1. What did you do?

from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from snowflake.sqlalchemy import URL

Later I tried connecting via sql alchemy:

from sqlalchemy import create_engine

engine = create_engine(
    'snowflake://{user}:{password}@{account}/'.format(
        user='<your_user_login_name>',
        password='<your_password>',
        account='<your_account_name>',
    )
)
try:
    connection = engine.connect()
    results = connection.execute('select current_version()').fetchone()
    print(results[0])
finally:
    connection.close()
    engine.dispose()
  1. What did you expect to see?

I was expecting to connect and start querying.

  1. Can you set logging to DEBUG and collect the logs?

    
    File <string>:2, in create_engine(url, **kwargs)

File ~/opt/miniconda3/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py:375, in deprecated_params..decorate..warned(fn, *args, *kwargs) 368 if m in kwargs: 369 _warn_with_version( 370 messages[m], 371 versions[m], 372 version_warnings[m], 373 stacklevel=3, 374 ) --> 375 return fn(args, **kwargs)

File ~/opt/miniconda3/lib/python3.9/site-packages/sqlalchemy/engine/create.py:522, in create_engine(url, **kwargs) 518 u = _url.make_url(url) 520 u, plugins, kwargs = u._instantiate_plugins(kwargs) --> 522 entrypoint = u._get_entrypoint() 523 dialect_cls = entrypoint.get_dialect_cls(u) 525 if kwargs.pop("_coerce_config", False):

File ~/opt/miniconda3/lib/python3.9/site-packages/sqlalchemy/engine/url.py:662, in URL._get_entrypoint(self) 660 else: 661 name = self.drivername.replace("+", ".") --> 662 cls = registry.load(name) 663 # check for legacy dialects that 664 # would return a module with 'dialect' as the 665 # actual class 666 if ( 667 hasattr(cls, "dialect") 668 and isinstance(cls.dialect, type) 669 and issubclass(cls.dialect, Dialect) 670 ):

File ~/opt/miniconda3/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py:330, in PluginLoader.load(self, name) 328 def load(self, name): 329 if name in self.impls: --> 330 return self.impls[name]() 332 if self.auto_fn: 333 loader = self.auto_fn(name)

File ~/opt/miniconda3/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py:349, in PluginLoader.register..load() 348 def load(): --> 349 mod = compat.import_(modulepath) 350 for token in modulepath.split(".")[1:]: 351 mod = getattr(mod, token)

ModuleNotFoundError: No module named 'snowflake'



<!--
If you need urgent assistance reach out to support for escalated issue processing https://community.snowflake.com/s/article/How-To-Submit-a-Support-Case-in-Snowflake-Lodge
-->
sfc-gh-mkeller commented 1 year ago

I don't see snowflake-sqlalchemy in the pip freeze output. Could you try installing it and trying again?

idomic commented 1 year ago

@sfc-gh-mkeller I did try both pacakges: snowflake-connector-python & snowflake-sqlalchemy


appnope==0.1.3
asn1crypto @ file:///home/conda/feedstock_root/build_artifacts/asn1crypto_1647369152656/work
asttokens==2.2.1
attrs==22.2.0
autopep8==2.0.2
backcall==0.2.0
backoff==2.2.1
black==23.3.0
bleach==6.0.0
brotlipy @ file:///Users/runner/miniforge3/conda-bld/brotlipy_1666764759924/work
certifi==2022.12.7
cffi @ file:///Users/runner/miniforge3/conda-bld/cffi_1671179893800/work
charset-normalizer @ file:///home/conda/feedstock_root/build_artifacts/charset-normalizer_1661170624537/work
click==8.1.3
comm==0.1.3
contourpy==1.0.7
cryptography @ file:///Users/runner/miniforge3/conda-bld/cryptography_1669593074946/work
cycler==0.11.0
debugpy==1.6.7
decorator==5.1.1
docutils==0.19
duckdb==0.7.1
duckdb-engine==0.7.0
exceptiongroup==1.1.1
executing==1.2.0
fastjsonschema==2.16.3
filelock @ file:///home/conda/feedstock_root/build_artifacts/filelock_1680834529360/work
flake8==6.0.0
fonttools==4.39.3
greenlet @ file:///Users/runner/miniforge3/conda-bld/greenlet_1674937749146/work
idna @ file:///home/conda/feedstock_root/build_artifacts/idna_1663625384323/work
importlib-metadata @ file:///home/conda/feedstock_root/build_artifacts/importlib-metadata_1679167925176/work
iniconfig==2.0.0
invoke==2.0.0
ipykernel==6.22.0
ipython==8.12.0
ipython-genutils==0.2.0
ipywidgets==8.0.6
jaraco.classes==3.2.3
jedi==0.18.2
Jinja2==3.1.2
jsonschema==4.17.3
-e git+https://github.com/ploomber/jupysql.git@dc034e95edc62513b3a28e39e4fb95dcb2f06086#egg=jupysql
jupyter_client==8.1.0
jupyter_core==5.3.0
jupyterlab-widgets==3.0.7
jupytext==1.14.5
keyring==23.13.1
kiwisolver==1.4.4
markdown-it-py==2.2.0
MarkupSafe==2.1.2
matplotlib==3.7.1
matplotlib-inline==0.1.6
mccabe==0.7.0
mdit-py-plugins==0.3.5
mdurl==0.1.2
monotonic==1.6
more-itertools==9.1.0
mypy-extensions==1.0.0
nbformat==5.8.0
nbqa==1.7.0
nest-asyncio==1.5.6
numpy @ file:///Users/runner/miniforge3/conda-bld/numpy_1675642719423/work
oscrypto==1.3.0
packaging @ file:///home/conda/feedstock_root/build_artifacts/packaging_1673482170163/work
pandas==2.0.0
parso==0.8.3
pathspec==0.11.1
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.5.0
pkginfo==1.9.6
pkgmt==0.3.0
platformdirs==3.2.0
ploomber-core==0.2.9
pluggy==1.0.0
polars==0.16.14
posthog==2.4.2
prettytable==3.6.0
prompt-toolkit==3.0.38
psutil==5.9.4
ptyprocess==0.7.0
pure-eval==0.2.2
pyarrow==11.0.0
pycodestyle==2.10.0
pycparser @ file:///home/conda/feedstock_root/build_artifacts/pycparser_1636257122734/work
pycryptodomex==3.17
pyflakes==3.0.1
Pygments==2.14.0
PyJWT @ file:///home/conda/feedstock_root/build_artifacts/pyjwt_1666240235902/work
pyodbc==4.0.35
pyOpenSSL==22.1.0
pyparsing==3.0.9
pyrsistent==0.19.3
PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1661604839144/work
pytest==7.2.2
python-dateutil==2.8.2
pytz @ file:///home/conda/feedstock_root/build_artifacts/pytz_1680088766131/work
PyYAML==6.0
pyzmq==25.0.2
readme-renderer==37.3
requests @ file:///home/conda/feedstock_root/build_artifacts/requests_1680286922386/work
requests-toolbelt==0.10.1
rfc3986==2.0.0
rich==13.3.3
six==1.16.0
snowflake-connector-python @ file:///Users/runner/miniforge3/conda-bld/snowflake-connector-python_1679650041988/work
snowflake-sqlalchemy==1.4.6
SQLAlchemy==1.4.47
sqlglot==11.5.2
sqlparse==0.4.3
stack-data==0.6.2
tokenize-rt==5.0.0
toml==0.10.2
tomli==2.0.1
tornado==6.2
traitlets==5.9.0
twine==4.0.2
typing_extensions @ file:///home/conda/feedstock_root/build_artifacts/typing_extensions_1678559861143/work
tzdata==2023.3
urllib3 @ file:///home/conda/feedstock_root/build_artifacts/urllib3_1678635778344/work
wcwidth==0.2.6
webencodings==0.5.1
widgetsnbextension==4.0.7
zipp @ file:///home/conda/feedstock_root/build_artifacts/zipp_1677313463193/work```
idomic commented 1 year ago

Alright, I was able to find the issue. The main thing was I was running on conda but I've used pip install... instead of conda install -c conda-forge snowflake-connector-python...

I also wanted to ask, how can we add a guide to connect directly from Jupyter (with JupySQL, not sqlalchemy)?

sfc-gh-dszmolka commented 8 months ago

bumped into this one while reviewing old issues. good to hear it was resolved for you.

regarding adding examples. JupySQL already seems to have a guide for Snowflake in their docs (which is I think the right place for it)