Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

python - Pyodbc - "Data source name not found, and no default driver specified"

I have trouble getting pyodbc work. I have unixodbc , unixodbc-dev, odbc-postgresql, pyodbc packages installed on my Linux Mint 14. I am losing hope to find solution on my own, any help appreciated. See details below:

Running:

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

Gives me:

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

# odbcinst -j gives:

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

Which makes me think there is a unixodbc configuration problem. Here are my unixodbc config file contents:

File /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

File /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        =

File ~/.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        =
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I believe the answer to your problem is that in your ~/.odbc.ini file you are saying to use driver PostgreSQL - but you have not defined that driver in your /etc/odbcinst.ini file. Try changing PostgreSQL to PostgreSQL ANSI or PostgreSQL Unicode (both of which are defined in /etc/odbcinst.ini).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...