Home > Software engineering >  Docker python:3.9.10-slim-buster image can not install backports.zoneinfo using pip
Docker python:3.9.10-slim-buster image can not install backports.zoneinfo using pip

Time:03-01

I have tried Containerising an django project. I was using python:alpine image. The app needed backports.zoneinfo to be installed as requirement. While running pip install -r requirements.txt its showing error when it try to install the backports.zoneinfo.

requirements.txt

asgiref==3.5.0
backports.zoneinfo==0.2.1
Django==4.0.2
sqlparse==0.4.2

Then I have opened docker container in interactive mode and tried pip install backports.zoneinfo. There also its showing same error.

I have tried the same commands in python:3.9.10 image. It was working fine and the package got installed. This error can be reproduced using any of slim, alpine images.

I have went through couple of fixes. But it wasn't working. Few of the fixes that I have tried are given below. I have tried these inside the container.

  • pip upgrade
  • pip upgrade wheel
  • apt/apk install gcc
  • apt/apk install gzdata
  • pip install python-dev-tools
  • apt/apk install gcc-c

To reproduce the error

Command

  1. docker pull python:alpine
  2. docker run -it python:alpine sh
  3. pip install backports.zoneinfo

Error

Collecting backports.zoneinfo
  Downloading backports.zoneinfo-0.2.1.tar.gz (74 kB)
     |████████████████████████████████| 74 kB 692 kB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: backports.zoneinfo
  Building wheel for backports.zoneinfo (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python /usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmprpnblifv
       cwd: /tmp/pip-install-tese9bhy/backports-zoneinfo_cf483b65d8814b8c8a8db93a7369c0cf
  Complete output (35 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.9
  creating build/lib.linux-x86_64-3.9/backports
  copying src/backports/__init__.py -> build/lib.linux-x86_64-3.9/backports
  creating build/lib.linux-x86_64-3.9/backports/zoneinfo
  copying src/backports/zoneinfo/_tzpath.py -> build/lib.linux-x86_64-3.9/backports/zoneinfo
  copying src/backports/zoneinfo/_zoneinfo.py -> build/lib.linux-x86_64-3.9/backports/zoneinfo
  copying src/backports/zoneinfo/_common.py -> build/lib.linux-x86_64-3.9/backports/zoneinfo
  copying src/backports/zoneinfo/__init__.py -> build/lib.linux-x86_64-3.9/backports/zoneinfo
  copying src/backports/zoneinfo/_version.py -> build/lib.linux-x86_64-3.9/backports/zoneinfo
  running egg_info
  writing src/backports.zoneinfo.egg-info/PKG-INFO
  writing dependency_links to src/backports.zoneinfo.egg-info/dependency_links.txt
  writing requirements to src/backports.zoneinfo.egg-info/requires.txt
  writing top-level names to src/backports.zoneinfo.egg-info/top_level.txt
  reading manifest file 'src/backports.zoneinfo.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  warning: no files found matching '*.png' under directory 'docs'
  warning: no files found matching '*.svg' under directory 'docs'
  no previously-included directories found matching 'docs/_build'
  no previously-included directories found matching 'docs/_output'
  adding license file 'LICENSE'
  adding license file 'licenses/LICENSE_APACHE'
  writing manifest file 'src/backports.zoneinfo.egg-info/SOURCES.txt'
  copying src/backports/zoneinfo/__init__.pyi -> build/lib.linux-x86_64-3.9/backports/zoneinfo
  copying src/backports/zoneinfo/py.typed -> build/lib.linux-x86_64-3.9/backports/zoneinfo
  running build_ext
  building 'backports.zoneinfo._czoneinfo' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/lib
  gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/local/include/python3.9 -c lib/zoneinfo_module.c -o build/temp.linux-x86_64-3.9/lib/zoneinfo_module.o -std=c99
  error: command 'gcc' failed: No such file or directory
  ----------------------------------------
  ERROR: Failed building wheel for backports.zoneinfo
ERROR: Could not build wheels for backports.zoneinfo which use PEP 517 and cannot be installed directly

CodePudding user response:

It's complaining about a missing file or directory. It's a bit misleading since it's gcc that's missing. In alpine, you'll also have to install musl-dev, too, to get all the required development files.

apk add -u gcc musl-dev

Also, python:alpine3.15 is using python3.10 which doesn't seem to be supported by backports.zoneinfo. https://github.com/pganssle/zoneinfo/issues/111

  • Related