Python sqlalchemy.exc.ArgumentError: 无法加载插件: sqlalchemy.dialects:driver

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15648814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 20:37:14  来源:igfitidea点击:

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

pythonsqlalchemypsycopg2alembic

提问by daydreamer

I am trying to run alembicmigration and when I run

我正在尝试运行alembic迁移,当我运行时

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 psycopg2installed in my virtualenv

我什至已经psycopg2安装在我的 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?

什么可能导致这个问题?

采纳答案by zzzeek

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.

所以我会说你实际上并没有使用你认为的 postgresql URL - 你可能正在某处调用默认生成的 alembic.ini。

回答by Gilad

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

回答by fiatjaf

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

对于那些没有注意到的人,zzzzeek所指的“默认生成的 alembic.ini”在项目的根目录中。

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

整个问题是sqlalchemy.urlalembic.ini文件中设置配置参数之一。此外,它可以以编程方式设置,如https://stackoverflow.com/a/15668175/973380 中所述

回答by Antti Haapala

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

请注意,该方案实际上并未指定驱动程序,而是指定方言:该方案的形式为dialect://ordialect+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).

例如,连接到 PostgreSQL 数据库的正确 url 将以例如postgres://(默认为 using psycopg2)或显式选择驱动程序(postgres+psycopg2://或其他驱动程序)开头。

If you happen to specify onlypsycopg2you will get the error

如果你碰巧指定psycopg2你会得到错误

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

回答by Tyger Guzman

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

让 Teradata 查询在 Pyinstaller 生成的 .exe 上运行。我将引擎从 SQLAlchemy 更改为 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") 

回答by jayko03

I did,

我做了,

pip install ibm_db_sa

it fixed problem

它解决了问题

回答by Uday

uninstall anaconda if you have it. it is installing your mysql connector in the anaconda path and your code is probably looking in the python path.

如果有 anaconda,请卸载它。它正在 anaconda 路径中安装您的 mysql 连接器,并且您的代码可能正在 python 路径中查找。