gpt4 book ai didi

python - 无法在 Python 镜像上找到包 msodbcsql

转载 作者:行者123 更新时间:2023-12-02 19:24:41 24 4
gpt4 key购买 nike

这是我第一次尝试使用 pyodbc 连接到 Docker 镜像中的 Azure SQL 数据库。我的 Dockerfile 如下所示:

# the base image
FROM python:3

WORKDIR /usr/src/app

COPY requirements.txt ./
COPY music_trends.py ./

# install SQL Server drivers
RUN apt-get update
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD [ "python", "./music_trends.py" ]

这会引发错误消息:

E: Unable to locate package msodbcsql
The command '/bin/sh -c apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev' returned a non-zero code: 100

我找到了 ubuntu:16.04 的分辨率,例如:https://github.com/Azure/azure-functions-docker/pull/45并尝试从我的 Dockerfile 运行 msodbcsql.msi 文件。

是否有针对 python:3 的等效修复?

最佳答案

python:3基于debian,所以引用microsoft doc :

您应该安装microsoft apt源,同时将msodbcsql更改为msodbcsql17,示例如下:

Dockerfile:

FROM python:3

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get install msodbcsql17 unixodbc-dev -y

2019-07-26 更新:

我没有注意到本月初官方 python:3 镜像从 debian 9 更新到 debian 10,请参阅 this

从上面的微软指南来看,目前他们似乎只是打包接下来的每个依赖项:

#Debian 8
curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Debian 9
curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list

当然你可以自己处理debian 10的依赖,比如libcrypto.so版本问题等,但我仍然建议你像微软一样使用python3 debian 9版本为你做了一切(PS:我认为他们会在不久的将来更新,因为 debian 10 半个月前发布,我想他们需要一些时间。顺便说一句,https://packages.microsoft .com/config/debian/10/prod.list 在那里,但目前没有包 msodbcsql17...)

因此,我建议您接下来最简单的方法是,与旧的 Dockerfile 相比,只需将 python:3 更改为 python:3-stretch code>,并安装apt-transport-https,在debian 9中默认不安装,详细信息如下:

Dockerfile:

FROM python:3-stretch

RUN apt-get update && \
apt-get install -y apt-transport-https && \
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get install msodbcsql17 unixodbc-dev -y

.所以检查:

root@91addb538736:/# ldd /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1
linux-vdso.so.1 (0x00007ffd72bd0000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4892696000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f489248e000)
libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 (0x00007f4892273000)
libcrypto.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2 (0x00007f4891e0d000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f4891b33000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f48918e8000)
libssl.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2 (0x00007f489167f000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f489147a000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f48910f8000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4890df4000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4890bdd000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f48909c0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4890621000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4892ca1000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f48903ee000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f48901ea000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f488ffde000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f488fdda000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f488fbc3000)

关于python - 无法在 Python 镜像上找到包 msodbcsql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57184825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com