我遇到了使用pyodbc
的问题。我在Linux Mint 14上安装了unixodbc
,unixodbc-dev
,odbc-postgresql
和pyodbc
软件包。
我已经失去了自行解决问题的希望,非常感谢任何帮助。以下是详细信息:
运行:
>>> 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 =