问题
I am trying to query ODBC compliant databases using pyodbc in ubuntu. For that, i have installed the driver (say mysql-odbc-driver). After installation the odbcinst.ini file with the configurations gets created in the location /usr/share/libmyodbc/odbcinst.ini When i try to connect to the database using my pyodbc connection code, i get a driver not found error message. Now when I copy the contents of the file to /etc/odbcinst.ini, it works!
This means pyodbc searches for the driver information in file /etc/odbcinst.ini.
How can I change the location where it searches the odbcinst.ini file for the driver information
Thanks.
回答1:
Assuming you are using unixODBC here was some possibilities:
- rebuild unixODBC from scratch and set --sysconfdir
- export ODBCSYSINI env var pointing to a directory and unixODBC will look here for odbcinst.ini and odbc.ini system dsns
- export ODBCINSTINI and point it at your odbcinst.ini file
BTW, I doubt pyodbc looks anything up in the odbcinst.ini file but unixODBC will. There is a list of ODBC Driver manager APIs which can be used to examine ODBC ini files.
来源:https://stackoverflow.com/questions/11393269/setting-the-location-where-pyodbc-searches-for-odbcinst-ini-file