【问题标题】:docker build python with lxml, wheel build failsdocker build python with lxml,wheel build 失败
【发布时间】:2021-08-18 01:37:26
【问题描述】:

我无法使用 sudo docker-compose up --build 构建一个将使用 lxml 构建的 docker 容器。

图片:尝试了以下没有运气: ubuntu,python3.9.5-buster-lite,python3.9.5

这是我的 docker-compose.yml 文件:

version: '3.8'
services:
  mycoolapp:
    container_name: 'coolapp'
    build:
      context: .
      dockerfile: Dockerfile.coolapp
    ports:
      - "80:80"

这是我的 docker 文件(我的 requirements.txt 列出了没有版本的“lxml”):

# pull official base image                                                                                                                                                                                                                    
FROM python:3.9.6-buster                                                                                                                                                                                                                      
                                                                                                                                                                                                                                              
#This is for lxml                                                                                                                                                                                                                             
RUN apt-get update; apt-get install -y python3-lxml                                                                                                                                                                                                                                                                                                                                                                                                                 
COPY requirements.txt /                                                                                                                                                                                                                       
RUN pip3 install -r /requirements.txt                                                                                                                                                                                                         
COPY . /app                                                                                                                                                                                                                                   
WORKDIR /app                                                                                                                                                                                                                                  
ENTRYPOINT ["./gunicorn_starter.sh"]          

除了在我上面的 Dockerfile.coolapp 中尝试 apt-get install -y python3-lxml 之外,我还尝试了以下但没有成功,全部来自 lxml 的 website

RUN apt-get update; apt-get install -y gcc libxml2-dev libxslt-dev python-dev                                                                                                                                                               
RUN apt-get update; apt-get install -y gcc g++ libxml2-dev libxslt-dev                                                                                                                                                                      
RUN pip3 install lxml 

docker 版本:Docker 版本 20.10.8,构建 3967b7d 构建是在它的旧树莓派 2b 上执行的。系统有 948308kb (~1GB) 的内存,所以速度很慢。

错误:每次尝试构建时都会出现以下两个错误。

  Building wheel for lxml (setup.py): started
  Building wheel for lxml (setup.py): still running...
  Building wheel for lxml (setup.py): finished with status 'error'
  Running setup.py clean for lxml
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-32cu6b3q/lxml_75dfbf51995e40dd9829fd90df4669cf/setup.py'"'"'; __file__='"'"'/tmp/pip-install-32cu6b3q/lxml_75dfbf51995e40dd9829fd90df4669cf/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-luxzc2gm
       cwd: /tmp/pip-install-32cu6b3q/lxml_75dfbf51995e40dd9829fd90df4669cf/
  Complete output (81 lines):
  Building lxml version 4.6.3.
  Building without Cython.
  Building against libxml2 2.9.4 and libxslt 1.1.32
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-armv7l-3.9
  creating build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/builder.py -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/doctestcompare.py -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/usedoctest.py -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/ElementInclude.py -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/__init__.py -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/cssselect.py -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/_elementpath.py -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/pyclasslookup.py -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/sax.py -> build/lib.linux-armv7l-3.9/lxml
  creating build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/__init__.py -> build/lib.linux-armv7l-3.9/lxml/includes
  creating build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/formfill.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/builder.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/_html5builder.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/usedoctest.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/soupparser.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/_setmixin.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/__init__.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/ElementSoup.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/clean.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/html5parser.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/diff.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/defs.py -> build/lib.linux-armv7l-3.9/lxml/html
  copying src/lxml/html/_diffcommand.py -> build/lib.linux-armv7l-3.9/lxml/html
  creating build/lib.linux-armv7l-3.9/lxml/isoschematron
  copying src/lxml/isoschematron/__init__.py -> build/lib.linux-armv7l-3.9/lxml/isoschematron
  copying src/lxml/etree.h -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/etree_api.h -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/lxml.etree.h -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/lxml.etree_api.h -> build/lib.linux-armv7l-3.9/lxml
  copying src/lxml/includes/xslt.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/xmlerror.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/config.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/__init__.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/dtdvalid.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/c14n.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/etreepublic.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/tree.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/xinclude.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/htmlparser.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/xpath.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/uri.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/schematron.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/relaxng.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/xmlschema.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/xmlparser.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/lxml-version.h -> build/lib.linux-armv7l-3.9/lxml/includes
  copying src/lxml/includes/etree_defs.h -> build/lib.linux-armv7l-3.9/lxml/includes
  creating build/lib.linux-armv7l-3.9/lxml/isoschematron/resources
  creating build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/rng
  copying src/lxml/isoschematron/resources/rng/iso-schematron.rng -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/rng
  creating build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl
  copying src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl
  copying src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl
  creating build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
  copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
  copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
  copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
  copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
  copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
  copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
  running build_ext
  building 'lxml.etree' extension
  creating build/temp.linux-armv7l-3.9
  creating build/temp.linux-armv7l-3.9/src
  creating build/temp.linux-armv7l-3.9/src/lxml
  gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -I/usr/include/libxml2 -Isrc -Isrc/lxml/includes -I/usr/local/include/python3.9 -c src/lxml/etree.c -o build/temp.linux-armv7l-3.9/src/lxml/etree.o -w
  gcc -pthread -shared -Wl,--strip-all build/temp.linux-armv7l-3.9/src/lxml/etree.o -L/usr/local/lib -lxslt -lexslt -lxml2 -lrt -lz -lm -o build/lib.linux-armv7l-3.9/lxml/etree.cpython-39-arm-linux-gnueabihf.so
  /usr/bin/ld: cannot find -lz
  collect2: error: ld returned 1 exit status
  error: command '/usr/bin/gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for lxml
Successfully built bs4 MarkupSafe
Failed to build lxml
Installing collected packages: soupsieve, MarkupSafe, Werkzeug, urllib3, Jinja2, itsdangerous, idna, click, chardet, certifi, beautifulsoup4, requests, lxml, gunicorn, Flask, bs4
    Running setup.py install for lxml: started
    Running setup.py install for lxml: still running...
    Running setup.py install for lxml: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-32cu6b3q/lxml_75dfbf51995e40dd9829fd90df4669cf/setup.py'"'"'; __file__='"'"'/tmp/pip-install-32cu6b3q/lxml_75dfbf51995e40dd9829fd90df4669cf/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-4c9_up7a/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/lxml
         cwd: /tmp/pip-install-32cu6b3q/lxml_75dfbf51995e40dd9829fd90df4669cf/
    Complete output (81 lines):
    Building lxml version 4.6.3.
    Building without Cython.
    Building against libxml2 2.9.4 and libxslt 1.1.32
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-armv7l-3.9
    creating build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/builder.py -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/doctestcompare.py -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/usedoctest.py -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/ElementInclude.py -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/__init__.py -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/cssselect.py -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/_elementpath.py -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/pyclasslookup.py -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/sax.py -> build/lib.linux-armv7l-3.9/lxml
    creating build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/__init__.py -> build/lib.linux-armv7l-3.9/lxml/includes
    creating build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/formfill.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/builder.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/_html5builder.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/usedoctest.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/soupparser.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/_setmixin.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/__init__.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/ElementSoup.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/clean.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/html5parser.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/diff.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/defs.py -> build/lib.linux-armv7l-3.9/lxml/html
    copying src/lxml/html/_diffcommand.py -> build/lib.linux-armv7l-3.9/lxml/html
    creating build/lib.linux-armv7l-3.9/lxml/isoschematron
    copying src/lxml/isoschematron/__init__.py -> build/lib.linux-armv7l-3.9/lxml/isoschematron
    copying src/lxml/etree.h -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/etree_api.h -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/lxml.etree.h -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/lxml.etree_api.h -> build/lib.linux-armv7l-3.9/lxml
    copying src/lxml/includes/xslt.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/xmlerror.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/config.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/__init__.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/dtdvalid.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/c14n.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/etreepublic.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/tree.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/xinclude.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/htmlparser.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/xpath.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/uri.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/schematron.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/relaxng.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/xmlschema.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/xmlparser.pxd -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/lxml-version.h -> build/lib.linux-armv7l-3.9/lxml/includes
    copying src/lxml/includes/etree_defs.h -> build/lib.linux-armv7l-3.9/lxml/includes
    creating build/lib.linux-armv7l-3.9/lxml/isoschematron/resources
    creating build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/rng
    copying src/lxml/isoschematron/resources/rng/iso-schematron.rng -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/rng
    creating build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl
    copying src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl
    copying src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl
    creating build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt -> build/lib.linux-armv7l-3.9/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    running build_ext
    building 'lxml.etree' extension
    creating build/temp.linux-armv7l-3.9
    creating build/temp.linux-armv7l-3.9/src
    creating build/temp.linux-armv7l-3.9/src/lxml
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -I/usr/include/libxml2 -Isrc -Isrc/lxml/includes -I/usr/local/include/python3.9 -c src/lxml/etree.c -o build/temp.linux-armv7l-3.9/src/lxml/etree.o -w
    gcc -pthread -shared -Wl,--strip-all build/temp.linux-armv7l-3.9/src/lxml/etree.o -L/usr/local/lib -lxslt -lexslt -lxml2 -lrt -lz -lm -o build/lib.linux-armv7l-3.9/lxml/etree.cpython-39-arm-linux-gnueabihf.so
    /usr/bin/ld: cannot find -lz
    collect2: error: ld returned 1 exit status
    error: command '/usr/bin/gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-32cu6b3q/lxml_75dfbf51995e40dd9829fd90df4669cf/setup.py'"'"'; __file__='"'"'/tmp/pip-install-32cu6b3q/lxml_75dfbf51995e40dd9829fd90df4669cf/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-4c9_up7a/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/lxml Check the logs for full command output.
WARNING: You are using pip version 21.1.3; however, version 21.2.4 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

我还应该注意,如果我尝试在我的其他 linux 机器上构建它,我不会遇到问题,但不知道为什么。

错误不是直截了当的。如果系统内存不足,读取在线轮子可能会失败,这是真的吗?有人有什么建议吗?

【问题讨论】:

    标签: docker build raspberry-pi lxml


    【解决方案1】:

    想通了。 不得不使用更新的 python 图像。在我的 Dockerfile.coolapp 中使用 FROM python3.9.6-buster 终于构建了。

    【讨论】:

      猜你喜欢
      • 2015-09-14
      • 2021-03-06
      • 2020-09-14
      • 1970-01-01
      • 2018-06-27
      • 2017-05-29
      • 1970-01-01
      • 2017-09-30
      • 2019-05-29
      相关资源
      最近更新 更多