0
votes

I'm trying to deploy a python app using Heroku, but I'm not able to install pycairo, which is added to requirements.txt file. I have used https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku-community/apt.tgz build-package to install required apt packages.

When I tried to install this package in Heroku bash using pip, it returned the same error.

Building wheel for pycairo (setup.py): started
     Building wheel for pycairo (setup.py): finished with status 'error'
     ERROR: Command errored out with exit status 1:
      command: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6rkzsy5d/pycairo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6rkzsy5d/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-0eopb8bo
          cwd: /tmp/pip-install-6rkzsy5d/pycairo/
     Complete output (35 lines):
     running bdist_wheel
     running build
     running build_py
     creating build
     creating build/lib.linux-x86_64-3.8
     creating build/lib.linux-x86_64-3.8/cairo
     copying cairo/__init__.py -> build/lib.linux-x86_64-3.8/cairo
     copying cairo/__init__.pyi -> build/lib.linux-x86_64-3.8/cairo
     copying cairo/py.typed -> build/lib.linux-x86_64-3.8/cairo
     running build_ext
     building 'cairo._cairo' extension
     creating build/temp.linux-x86_64-3.8
     creating build/temp.linux-x86_64-3.8/cairo
     gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=19 -DPYCAIRO_VERSION_MICRO=1 -I/tmp/build_5896cd7c39526a1767b861fb4950464e/.apt/usr/include/cairo -I/tmp/build_5896cd7c39526a1767b861fb4950464e/.apt/usr/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/app/.heroku/python/include/python3.8 -c cairo/device.c -o build/temp.linux-x86_64-3.8/cairo/device.o -Wall -Warray-bounds -Wcast-align -Wconversion -Wextra -Wformat=2 -Wformat-nonliteral -Wformat-security -Wimplicit-function-declaration -Winit-self -Winline -Wmissing-format-attribute -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpacked -Wpointer-arith -Wreturn-type -Wshadow -Wsign-compare -Wstrict-aliasing -Wundef -Wunused-but-set-variable -Wswitch-default -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-command-line-argument -fno-strict-aliasing -fvisibility=hidden -std=c99


/usr/bin/ld: final link failed: Bad value
           collect2: error: ld returned 1 exit status
           error: command 'gcc' failed with exit status 1
           ----------------------------------------
       ERROR: Command errored out with exit status 1: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6rkzsy5d/pycairo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6rkzsy5d/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-lbe5cexs/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.8/pycairo Check the logs for full command output.
 !     Push rejected, failed to compile Python app.
 !     Push failed
1

1 Answers

0
votes

Please don't link the archive file (.tgz) of the buildpack, but its homepage from here.

In the error output you posted, the build_ext function of the Python Setuptools build system fails to build cairo. In particular, the gcc compiler tells you that the ld linker failed. I guess it's because the script in the buildpack didn't link the cairo library.

I think you have 2 options:

  1. Modify the Heroku buildpack and figure out how to install the cairo C library and link it when Pycairo runs the build_ext function.
  2. Create a Dockerimage that includes the conda package manager (I would start from docker-miniconda) and install Pycairo as a conda recipe.

Option 2 should be far easier.

See also my other answer here.