问题
I have python 2.7 32 bit running on a Windows 8.1 64 bit machine.
I have Access 2013 and a .accdb file that I'm trying to access from python and pyodbc.
I can create a 64 bit DSN in the 64 bit ODBC manager. However, when I try to connect to it from python, I get the error:
Error: (u'IM002', u'[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified')
Presumably, python is only looking for 32-bit DSNs and doesn't find the 64-bit one that I've created.
When I try to create a 32-bit DSN within the 32-bit ODBC manager, there is no driver for a accdb file (just .mdb).
I think I need a 32 bit ODBC driver for Access 2013 files (.accdb), but haven't been able to find one.
Is it possible to do what I'm trying to do? -- 32bit python access a Access 2013 .accdb file?
回答1:
32 bit applications including Python can work only with 32 bit ODBC drivers.
64 bit applications including Python can work only with 64 bit ODBC drivers.
If you have:
- 32 bit Python with
pyodbc
module - 64 bit MS Access ODBC driver
Then you must change something:
- You can install 64 bit version of Python (I use Active Python which has
odbc
module), then you can use 64 bit version ofpyodbc
module (I see it for Python 2.6, 2.7 and 3.3) - You can install 32 bit version od MS Access driver
Using pyodbc.dataSources()
you can list ODBC sources:
sources = pyodbc.dataSources()
dsns = list(sources.keys())
dsns.sort()
sl = []
for dsn in dsns:
sl.append('%s [%s]' % (dsn, sources[dsn]))
print('\n'.join(sl))
If you use ActiveState Python then you can list them using odbc
module as in my recipe: http://code.activestate.com/recipes/578782-printing-list-of-odbc-data-sources/?in=user-186902
回答2:
I had this same issue. For me, the problem was that I have 32 python and 32 bit pyodbc and 32 bit MS Access. But the pyqt application I created would not run on computers with 64 bit Access.
My solution was to install the 32 bit Access driver (as mentioned by Mikal) found here... http://www.microsoft.com/en-us/download/details.aspx?id=13255 at the command prompt using the "/passive" option. Otherwise, it wouldn't install.
For instance, C:\Downloads\AccessDatabaseEngine.exe /passive The driver is installed and now my application works on the host computer without issue.
There may or may not be issues with both the 32 bit and 64 bit Access drivers being installed. So far, I have not seen any.
回答3:
Trial and error showed that installing the "Access Database Engine" 2007 seemed to create 32-bit ODBC source for Access accdb files.
来源:https://stackoverflow.com/questions/21393558/32-bit-pyodbc-reading-64-bit-access-accdb