小编典典

Pyodbc-“找不到数据源名称,并且未指定默认驱动程序”

python

pyodbc上班很麻烦 我有unixodbcunixodbc-devodbc- postgresqlpyodbc安装在我的Linux Mint的14。我的包我失去希望找到我自己的解决方案,任何帮助表示赞赏。请参阅以下详细信息:

运行:

>>> import pyodbc
>>> conn = pyodbc.connect("DRIVER={PostgreSQL};SERVER=localhost;DATABASE=test;USER=openerp;OPTION=3;")

给我:

>>> pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')

#odbcinst -j给出

unixODBC 2.2.14
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/atman/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2

这使我认为存在unixodbc配置问题。这是我的unixodbc配置文件内容:

档案 /etc/odbcinst.ini

[PostgreSQL ANSI]
Description     = PostgreSQL ODBC driver (ANSI version)
Driver      = psqlodbca.so
Setup       = libodbcpsqlS.so
Debug       = 0
CommLog     = 1
UsageCount      = 2

[PostgreSQL Unicode]
Description     = PostgreSQL ODBC driver (Unicode version)
Driver      = psqlodbcw.so
Setup       = libodbcpsqlS.so
Debug       = 0
CommLog     = 1
UsageCount      = 2

档案 /etc/odbc.ini

[PostgreSQL test]
Description         = PostgreSQL 
Driver              = PostgreSQL ANSI
Trace               = No
TraceFile           = /tmp/psqlodbc.log
Database            = template1
Servername          = localhost
UserName            =
Password            =
Port                =
ReadOnly            = Yes
RowVersioning       = No
ShowSystemTables    = No
ShowOidColumn       = No
FakeOidIndex        = No
ConnSettings        =

档案 ~/.odbc.ini

[DEFAULT]
Driver = PostgreSQL

[PostgreSQL]
Description         = Test to Postgres
Driver              = PostgreSQL
Trace               = Yes
TraceFile           = sql.log
Database            = nick
Servername          = localhost
UserName            =
Password            =
Port                = 5432
Protocol            = 6.4
ReadOnly            = No
RowVersioning       = No
ShowSystemTables    = No
ShowOidColumn       = No
FakeOidIndex        = No
ConnSettings        =

阅读 147

收藏
2020-12-20

共1个答案

小编典典

我相信您问题的答案是,您在〜/
.odbc.ini文件中使用驱动程序PostgreSQL-但是您尚未在/etc/odbcinst.ini文件中定义该驱动程序。尝试更改PostgreSQLPostgreSQL ANSIPostgreSQL Unicode(两者均在/etc/odbcinst.ini中定义)。

2020-12-20