如何在 Alpine Linux Docker 容器中安装 "Microsoft Access Driver (*.mdb, *.accdb)" 驱动程序

How to install "Microsoft Access Driver (*.mdb, *.accdb)" driver in Alpine Linux Docker Container

查找所有驱动程序的脚本

我创建了一个脚本来查找所有 'pyodbc' 个驱动程序:

import pyodbc

print([x for x in pyodbc.drivers()])

问题

在我的主机中(Windows 安装了驱动程序),当我 运行 我得到所有 x64 驱动程序时:

> ['SQL Server', 'ODBC Driver 17 for SQL Server', 'Microsoft Access Driver (*.mdb, *.accdb)', 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)', 'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)', 'Microsoft Access Text Driver (*.txt, *.csv)']

但是,当我使用 Docker

FROM python:3.8-alpine

# Add dependencies
RUN apk upgrade
RUN apk add --no-cache curl gcc g++ unixodbc-dev
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h

WORKDIR /app

# Install Python dependencies
COPY requirements.txt ./
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Run script
COPY find_drivers.py find_drivers.py
CMD [ "python3", "find_drivers.py" ]

未找到驱动程序:

> []

参考资料

在此 Docker 映像中安装“Microsoft Access 驱动程序(*.mdb、*.accdb)”的最佳方法是什么?

What the best way to install "Microsoft Access Driver (*.mdb, *.accdb)" in this [Alpine Linux] Docker image?

你不能。 Microsoft 仅为 Windows 平台提供“Microsoft Access Driver (*.mdb, *.accdb)”(不像他们的 SQL Server 的 ODBC 驱动程序可用于 Windows, Linux, 和 Mac).

这里讨论了一些备选方案:

Working with an Access database in Python on non-Windows platform (Linux or Mac)