Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 743
Hana Avatar asked Nov 13 '18 15:11

Hana


People also ask

How do you connect snowflakes to SQLAlchemy?

To connect to Snowflake using SQLAlchemy, the process is as follows: Conda or Pip install the sqlalchemy Python package. Create connection string using Snowflake user credentials. Use the function create_engine to create a connection engine.

Does SQLAlchemy work with Snowflake?

As much as possible, Snowflake SQLAlchemy provides compatible functionality for SQLAlchemy applications.

What is dialect in SQLAlchemy?

The dialect is the system SQLAlchemy uses to communicate with various types of DBAPI implementations and databases. The sections that follow contain reference documentation and notes specific to the usage of each backend, as well as notes for the various DBAPIs.


2 Answers

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.

like image 51
Jake Z Avatar answered Sep 18 '22 05:09

Jake Z


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
like image 25
Shivendra Rajawat Avatar answered Sep 18 '22 05:09

Shivendra Rajawat