我如何在docker中安装lxml [英] How can I install lxml in docker

查看:488
本文介绍了我如何在docker中安装lxml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在docker中部署我的python项目,我在requirments.txt中写了lxml>=3.5.0,因为该项目需要lxml.这是我的Dockfile:

I want to deploy my python project in docker, I wrote lxml>=3.5.0 in the requirments.txt as the project needs lxml. Here is my dockfile:

FROM gliderlabs/alpine:3.3
RUN set -x \
    && buildDeps='\
        python-dev \
        py-pip \
        build-base \
    ' \
    && apk --update add python py-lxml $buildDeps \
    && rm -rf /var/cache/apk/* \
    && mkdir -p /app
ENV INSTALL_PATH /app
WORKDIR $INSTALL_PATH
COPY requirements-docker.txt ./
RUN pip install -r requirements.txt
COPY . .
RUN apk del --purge $buildDeps
ENTRYPOINT ["celery", "-A", "tasks", "worker", "-l", "info", "-B"]

当我将它部署到docker时,我得到了它:

I got this when I deploy it to docker:

*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'gcc' failed with exit status 1
----------------------------------------
Rolling back uninstall of lxml

尽管是因为'python-dev'和'python-lxml',但我还是这样编辑了停靠文件:

I though it was because 'python-dev' and 'python-lxml', then I edited the dockfile like this:

WORKDIR $INSTALL_PATH
COPY requirements-docker.txt ./
RUN apt-get build-dev python-lxml
RUN pip install -r requirements.txt

它不起作用,我又遇到了一个错误:

It did not work, and I got another error:

---> Running in 73201a0dcd59
/bin/sh: apt-get: not found

如何在docker中正确安装lxml?

How can I install lxml correctly in docker?

推荐答案

我在RUN pip install -r requirements.txt之前添加了RUN apk add --update --no-cache g++ gcc libxslt-dev,它起作用了.

I added RUN apk add --update --no-cache g++ gcc libxslt-dev before RUN pip install -r requirements.txt and it worked.

这篇关于我如何在docker中安装lxml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆