clickhouse-sqlalchemy icon indicating copy to clipboard operation
clickhouse-sqlalchemy copied to clipboard

how to registry.register clickhouse-sqlalchemy to normally use it

Open flyly0755 opened this issue 3 years ago • 4 comments

now i meet one problem after packaging project code with pyinstaller. uri = f"clickhouse://{user}:{password}@{host}:{port}/{database}" engine = create_engine(uri, echo=False, poolclass=NullPool) -------with this code raise error: Please check the system service:Can't load plugin: sqlalchemy.dialects:clickhouse. seems need to registry.register first then to create_engine, but don't know how to write it:( registry.register('clickhouse', 'clickhouse_sqlalchemy', 'dialect')---raise error: error:module 'clickhouse_sqlalchemy' has no attribute 'dialect' how to write? thanks in advance!!!

flyly0755 avatar Jun 13 '22 09:06 flyly0755

Dialects registration takes place in setup.py: https://github.com/xzkostyan/clickhouse-sqlalchemy/blob/master/setup.py#L94. It seems something wrong with your installation.

xzkostyan avatar Jun 13 '22 10:06 xzkostyan

yes, there is some issue with installation, now need to debug it. we use pyinstaller to pack codebase, using mange.spec as package configuration. add clickhouse_sqlalchemy into hiddenimports list in manage.spec, if not, will raise error no module named "clickhouse_sqlalchemy" found after packaging and using. maybe some thing wrong with hiddenimports

flyly0755 avatar Jun 15 '22 01:06 flyly0755

find some clue with https://snowflakecommunity.force.com/s/question/0D50Z00009Huss0SAB/how-to-get-pyinstaller-to-pack-snowflake-sqlalchemy-dialect, maybe change hook-sqlalchemy.py of pyinstaller with this line hiddenimports = ['pysqlite2', 'MySQLdb', 'psycopg2', 'sqlalchemy.ext.baked'] change to hiddenimports = ['pysqlite2', 'MySQLdb', 'psycopg2', 'sqlalchemy.ext.baked', 'clickhouse-sqlalchemy'] how do you guys think?

flyly0755 avatar Jun 15 '22 03:06 flyly0755

find solution from source code:) the link showed as below: https://github.com/xzkostyan/clickhouse-sqlalchemy/blob/master/tests/config.py register method as below when packaging with pyinstaller from sqlalchemy.dialects import registry registry.register( "clickhouse", "clickhouse_sqlalchemy.drivers.http.base", "dialect" )

flyly0755 avatar Jun 17 '22 08:06 flyly0755