First, use brew to install unixodbc and mdbtools. unixodbc is the odbc Driver Manager. mdbtools provides a set of mdb operation tools. More importantly, mdbtools provides mdb drivers.
$ Brew install unixodbc
$ Brew install mdbtools
However, after the installation is complete, the mdbtools driver dynamic link library libmdbodbc. dylib is not found in the/usr/local/lib directory.
You can view the mdbtools options and find that:
$ Brew options mdbtools
-- With-man-pages
Build manual pages
Mdbtools formula does not provide the -- with-unixodbc option. By default, the mdb driver is not built. Therefore, you need to manually compile and install the mdb driver provided by mdbtools.
Compile and install libmdbodbc
When installing mdbtools, brew has downloaded the mdbtools source package to the/Library/Caches/Homebrew/Directory. Therefore, you can directly compile and install this source package.
$ Tar zxvf mdbtools-0.7.1
$ Mdbtools-0.7.1 cd
$ Autoreconf-I-f
$./Configure -- with-unixodbc =/usr/local -- disable-man
$ Make
$ Cd src/odbc
$ Sudo make install
In this way, the libmdbodbc driver is installed in the/usr/local/lib directory. The source code of libmdbodbc is in the src/odbc directory.
Configure unixodbc
Because all brew packages are installed under/usr/local, the odbcinst. ini and odbc. ini files under the/usr/local/etc/directory should be configured here.
The odbcinst. ini configuration is as follows:
[MDBTools]
Description = MDBTools Driver
Driver = libmdbodbc. dylib
Setup = libmdbodbc. dylib
FileUsage = 1
UsageCount = 1
Then you can access the mdb file like on the linux platform.
$ Python3
>>> Import pypyodbc
>>> Conn = pypyodbc. connect ('driver = MDBTools; DBQ =/path/to/record. mdb ')
Because the odbc driver provided by mdbtools is used here, Chinese character encoding conversion still exists when used with pypyodbc. Please parameter: pypyodbc in linux to read Chinese garbled characters in the GB-encoded mdb solution.