sqlalchemy.exc.ArgumentError: Can't load plugin: sqlalchemy.dialects:driver

ぃ、小莉子 提交于 2019-12-23 06:47:11

问题


I am trying to run alembic migration and when I run

alembic revision --autogenerate -m "Added initial tables"

It fails saying

sqlalchemy.exc.ArgumentError: Can't load plugin: sqlalchemy.dialects:driver

the database url is

postgresql+psycopg2://dev:passwd@localhost/db

and I even have psycopg2 installed in my virtualenv

$yolk -l
Flask-Login     - 0.1.3        - active
Flask-SQLAlchemy - 0.16         - active
Flask           - 0.9          - active
Jinja2          - 2.6          - active
Mako            - 0.7.3        - active
MarkupSafe      - 0.15         - active
Python          - 2.7.2        - active development (/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload)
SQLAlchemy      - 0.8.0        - active
Werkzeug        - 0.8.3        - active
alembic         - 0.4.2        - active
antiorm         - 1.1.1        - active
appscript       - 1.0.1        - active
distribute      - 0.6.27       - active
envoy           - 0.0.2        - active
osascript       - 0.0.4        - active
pep8            - 1.4.5        - active
pip             - 1.1          - active
psycopg2        - 2.4.6        - active
wsgiref         - 0.1.2        - active development (/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7)
yolk            - 0.4.3        - active

Whay could be causing this issue?


回答1:


Here's how to produce an error like that:

>>> from sqlalchemy import *
>>> create_engine("driver://")
Traceback (most recent call last):
... etc
sqlalchemy.exc.ArgumentError: Can't load plugin: sqlalchemy.dialects:driver

so I'd say you aren't actually using the postgresql URL you think you are - you probably are calling upon a default-generated alembic.ini somewhere.




回答2:


For those who haven't noticed it, the "default-generated alembic.ini" zzzzeek refers to is in the root directory of the project.

The whole problem is one of setting the sqlalchemy.url config parameter in the alembic.ini file. Also, it can be set programmatically as explained in https://stackoverflow.com/a/15668175/973380.




回答3:


Notice that the scheme doesn't actually specify the driver but the dialect: the scheme is of form dialect:// or dialect+driver://.

For example the correct urls to connect to a PostgreSQL database would start with for example postgres:// (which defaults to using psycopg2), or choosing a driver explicitly (postgres+psycopg2://, or with another driver).

If you happen to specify only psycopg2 you will get the error

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:psycopg2



回答4:


Try those commands to install missing packages:

sudo apt-get install libpq-dev 
sudo pip install psycopg2 
sudo pip install redshift-sqlalchemy 
sudo pip install sqlparse



回答5:


To get the Teradata Queries to run on the .exe produced by Pyinstaller. I changed my engine from SQLAlchemy to Teradata

From :

import sqlalchemy as sa
user, pasw, hostname = UserName,Password, 'myurl.com'
# connect
td_engine = sa.create_engine('teradata://{}:{}@{}:22/'.format(user,pasw,hostname),echo=True)
df = pd.read_sql_query(query1,connect)

To:

import teradata
user, pasw, hostname = UserName,Password, 'myurl.com'
td = teradata.UdaExec (appName="test", version="1.0", logConsole=True)
td_engine = td.connect(method="odbc",system=hostname, username=user,password=pasw,driver="Teradata") 



回答6:


I did,

pip install ibm_db_sa

it fixed problem



来源:https://stackoverflow.com/questions/15648814/sqlalchemy-exc-argumenterror-cant-load-plugin-sqlalchemy-dialectsdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!