17

I've installed all the necessary packages:

pip install --upgrade snowflake-sqlalchemy

I am running this test code from the snowflake docs:

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

My output should be the snowflake version e.g. 1.48.0

But I get the error

NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:snowflake

(I am trying to run this in Anaconda)

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Hana
  • 1,330
  • 4
  • 23
  • 38
  • 1
    I faced the same problem too. But after I upgraded `snowflake-sqlalchemy` using the command line you wrote above, the connection was successful. – Sahar Jan 22 '19 at 21:40
  • facing the same error message and no solution yet even after I upgraded `snowflake-sqlalchemy` – mongotop Jun 27 '19 at 19:50

6 Answers6

14

I had similar issues when I tried to deploy code to an Azure Function App. sqlalchemy would find the module when I ran the code locally, but it failed to resolve the dialect on remote deployment and execution.

I resolved the issue there by running the following before calling create_engine:

from sqlalchemy.dialects import registry

...

registry.register('snowflake', 'snowflake.sqlalchemy', 'dialect')

I suspect that snowflake-sqlalchemy fails to self-register in certain environments.

Jake Z
  • 1,520
  • 1
  • 17
  • 26
  • Mine is the opposite. Works in my azure function (docker container) but not locally (outside of the docker container) – mwilson Dec 10 '20 at 18:13
5

This error generally appears due to a bad installation of the sqlalchemy package. Check the sqlalchemy.dialects folder to ensure that your dbapi folder exists.

Try to upgrade your sqlalchemy package:

pip install --upgrade sqlalchemy
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
4

pip install --upgrade snowflake-sqlalchemy worked for me

https://docs.snowflake.com/en/user-guide/sqlalchemy.html#installing-snowflake-sqlalchemy

Will H
  • 409
  • 4
  • 8
3

Try adding a couple additional imports:

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

This fixed the issue for me.

M.Cush
  • 201
  • 3
  • 6
1

I was deploying through serverless using pythonRequirements and has the same issue.

I removed the slim option and it worked, but I don't like it because it makes the zip file for my amazon lambda bigger. I just want to let others know there might be something wrong with the slim option.

misterone
  • 191
  • 2
  • 9
0

Maybe you are using conda? Then

conda install --yes snowflake-sqlalchemy

Note, it also still requires snowflake-connector-python being installed as well!

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
  • PackagesNotFoundError: The following packages are not available from current channels: - snowflake-sqlalchemy – staticor Aug 14 '20 at 03:30
  • All needed to do was to install snowflake-sqlalchemy. In my case used pip asI am not using conda. pip install snowflake-sqlalchemy. You may need to uninstalled. – Jorge Jan 31 '23 at 17:10