[英]Cannot install pyodbc in docker and getting error command 'gcc' failed with exit status 1
I'm trying install pyodbc in docker running inside linux container But I'm getting the following error我正在尝试在 linux 容器内运行的 docker 中安装 pyodbc 但我收到以下错误
Click here to view the image点击这里查看图片
src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
#include <sql.h>
^~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pyodbc
Here is my dockerfile这是我的码头文件
FROM mcr.microsoft.com/azure-functions/python:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
FROM ubuntu
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get -y install gcc mono-mcs && \
rm -rf /var/lib/apt/lists/*
FROM python
RUN apt-get update && apt-get install -y python3-pip
# RUN /usr/bin/pip -r /home/site/wwwroot/requirements.txt
# WORKDIR /home/site/wwwroot
COPY --from=0 /home/site/wwwroot /home/site/wwwroot
RUN cd /home/site/wwwroot && pip install -r requirements.txt
Note: I'm going push the code to the azure functionapp in linux machine注意:我要将代码推送到 linux 机器中的 azure functionapp
I had the same issue, I added the below code in my docker file, and it started working.我有同样的问题,我在我的 docker 文件中添加了以下代码,它开始工作。 Microsoft docker image is missing
unixodbc-dev
, so you need to install separately using the below command. Microsoft docker 映像缺少
unixodbc-dev
,因此您需要使用以下命令单独安装。
RUN apt-get update && apt-get install -y --no-install-recommends \
unixodbc-dev \
unixodbc \
libpq-dev
This is the setup that worked for me:这是对我有用的设置:
# pull official base image
FROM python:3.9.2-slim-buster
# install system dependencies
RUN apt-get update \
&& apt-get -y install gcc \
&& apt-get -y install g++ \
&& apt-get -y install unixodbc unixodbc-dev \
&& apt-get clean
And the pyodbc package was installed successfully.并且pyodbc包安装成功。
The error is:错误是:
src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
#include <sql.h>
This is telling you that you are missing a file sql.h
.这告诉您您缺少文件
sql.h
。 Looking at the documentation for PyODBC , it appears to require the UnixODBC development environment.查看 PyODBC 的文档,它似乎需要 UnixODBC 开发环境。
There are installation instructions at the above link for most major distributions.大多数主要发行版的上述链接都有安装说明。 You will need to update your Dockerfile to install the
unixodbc-dev
package.您需要更新 Dockerfile 以安装
unixodbc-dev
软件包。
This link is also helpful, you are missing mandatory files to needed to install.此链接也很有帮助,您缺少安装所需的强制性文件。 Add the below command for Debain to Dockerfile , the link has all solutions
将 Debain 的以下命令添加到 Dockerfile ,该链接包含所有解决方案
RUN apt-get update && apt-get install -y gcc unixodbc-dev运行 apt-get update && apt-get install -y gcc unixodbc-dev
https://github.com/mkleehammer/pyodbc/issues/165 https://github.com/mkleehammer/pyodbc/issues/165
The consolidated list of dependencies needed for pyodbc can be found in the documentation.可以在文档中找到 pyodbc 所需的依赖项的综合列表。 Make sure all of these are installed.
确保所有这些都已安装。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.