postgresql – Pyodbc – “找不到数据源名称,没有指定默认驱动程序”

前端之家收集整理的这篇文章主要介绍了postgresql – Pyodbc – “找不到数据源名称,没有指定默认驱动程序”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有麻烦pyodbc工作。我有unixodbc,unixodbc-dev,odbc-postgresql,pyodbc包安装在我的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 give:

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        =
我相信你的问题的答案是,在你的〜/ .odbc.ini文件,你说要使用驱动程序Postgresql – 但你没有在/etc/odbcinst.ini文件中定义该驱动程序。尝试将Postgresql更改为Postgresql ANSI或Postgresql Unicode(两者都在/etc/odbcinst.ini中定义)。
原文链接:https://www.f2er.com/postgresql/193316.html

猜你在找的Postgre SQL相关文章