faas-cli : function build error with numPy for python function

Created on 19 Mar 2018  路  5Comments  路  Source: openfaas/faas

Expected Behaviour

The function should build successfully

Current Behaviour

The function fails to build.

Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_5Fp5u/numpy/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-W9MMPP-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-_5Fp5u/numpy/
You are using pip version 9.0.1, however version 9.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
2018/03/19 13:22:31 ERROR - Could not execute command: [docker build -t saad749/matrix-compute .]

kmaster@kmaster:~/functions$ sudo faas-cli build -f ./matrix-compute.yml
[0] > Building matrix-compute.
Clearing temporary build folder: ./build/matrix-compute/
Preparing ./matrix-compute/ ./build/matrix-compute/function
Building: saad749/matrix-compute with python template. Please wait..
Sending build context to Docker daemon 8.192 kB
Step 1/16 : FROM python:2.7-alpine
 ---> 0781c116c406
...
...
      File "/usr/local/lib/python2.7/distutils/command/build.py", line 127, in run
        self.run_command(cmd_name)
      File "/usr/local/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/tmp/pip-build-yPZscR/numpy/numpy/distutils/command/build_src.py", line 148, in run
        self.build_sources()
      File "/tmp/pip-build-yPZscR/numpy/numpy/distutils/command/build_src.py", line 159, in build_sources
        self.build_library_sources(*libname_info)
      File "/tmp/pip-build-yPZscR/numpy/numpy/distutils/command/build_src.py", line 294, in build_library_sources
        sources = self.generate_sources(sources, (lib_name, build_info))
      File "/tmp/pip-build-yPZscR/numpy/numpy/distutils/command/build_src.py", line 377, in generate_sources
        source = func(extension, build_dir)
      File "numpy/core/setup.py", line 675, in get_mathlib_info
        raise RuntimeError("Broken toolchain: cannot link a simple C program")
    RuntimeError: Broken toolchain: cannot link a simple C program

    ----------------------------------------
Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-yPZscR/numpy/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-eEtQH7-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-yPZscR/numpy/
You are using pip version 9.0.1, however version 9.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
2018/03/19 13:14:24 ERROR - Could not execute command: [docker build -t saad749/matrix-compute .]

Steps to Reproduce (for bugs)


  1. Requirements.txt
requests
  1. handler.py
import numpy as np
import requests
from io import BytesIO

def handle(req):
    # Whatever
    print(req)
  1. sudo faas-cli build -f ./matrix-compute.yml

Context

The function is multiplying two matrices that have been fetched from a remote server.

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
Client:
 Version:      1.13.1
 API version:  1.26
 Go version:   go1.8.3
 Git commit:   092cba3
 Built:        Thu Oct 12 22:34:44 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.13.1
 API version:  1.26 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   092cba3
 Built:        Thu Oct 12 22:34:44 2017
 OS/Arch:      linux/amd64
 Experimental: false
  • Are you using Docker Swarm or Kubernetes (FaaS-netes)? Kubernetes

  • Operating System and version (e.g. Linux, Windows, MacOS): Ubuntu

Most helpful comment

Thank you for the quick replies.
@alexellis Yes, using python3-debian template solves it.

All 5 comments

@saad749 Thank you for including the console output, however, it is not clear what the "Current Behavior" is without having to read through most of the console output.

That being said, I did notice this line in the output:

Building wheels for collected packages: numpy
Running setup.py bdist_wheel for numpy: started
Running setup.py bdist_wheel for numpy: finished with status 'error'

It appears the problem is trying to use the package numpy on Apline Linux (which is the base image in the function template)

I am not familiar with Python, but doing a quick search, I was able to find this SO answer that may help solve your issue: https://stackoverflow.com/a/33424723/8417912

Alternatively, you could try a different base image in the function.

I'm going to trim down the output as it makes the issue hard to read.

Numpy needs a build toolchain including GCC etc which is not in the minimal standard templates. The easiest way of getting to numpy would be to use the Python3 Debian template instead.

$ faas template pull https://github.com/openfaas-incubator/python3-debian
$ faas new --lang python3-debian numpy-test

@saad749 do you want to give it a shot and get back to us?

Thank you for the quick replies.
@alexellis Yes, using python3-debian template solves it.

Glad you got it working!

Derek close

Was this page helpful?
0 / 5 - 0 ratings

Related issues

derailed picture derailed  路  6Comments

alexellis picture alexellis  路  5Comments

alexellis picture alexellis  路  7Comments

matthewdolman picture matthewdolman  路  5Comments

FlankMiao picture FlankMiao  路  4Comments