Install numpy on LEDE 17.01.4

Hi all, I'm new to LEDE, I've got a Netgear R8000 (arm cortex a9 series CPU) router, and I've successfully installed python3.6, pip3, gcc on it. But when I tried to install numpy by pip3 install numpy, it raised an error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-tzfse4e_/numpy/setup.py", line 394, in <module>
    setup_package()
  File "/tmp/pip-build-tzfse4e_/numpy/setup.py", line 386, in setup_package
    setup(**metadata)
  File "/tmp/pip-build-tzfse4e_/numpy/numpy/distutils/core.py", line 169, in setup
    return old_setup(**new_attr)
  File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/tmp/pip-build-tzfse4e_/numpy/numpy/distutils/command/install.py", line 62, in run
    r = self.setuptools_run()
  File "/tmp/pip-build-tzfse4e_/numpy/numpy/distutils/command/install.py", line 36, in setuptools_run
    return distutils_install.run(self)
  File "/usr/lib/python3.6/distutils/command/install.py", line 545, in run
    self.run_command('build')
  File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/tmp/pip-build-tzfse4e_/numpy/numpy/distutils/command/build.py", line 47, in run
    old_build.run(self)
  File "/usr/lib/python3.6/distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/tmp/pip-build-tzfse4e_/numpy/numpy/distutils/command/build_src.py", line 148, in run
    self.build_sources()
  File "/tmp/pip-build-tzfse4e_/numpy/numpy/distutils/command/build_src.py", line 159, in build_sources
    self.build_library_sources(*libname_info)
  File "/tmp/pip-build-tzfse4e_/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-tzfse4e_/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/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-tzfse4e_/numpy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-xlubx0sk-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-tzfse4e_/numpy/

I googled everywhere but still can't find a solid fix to my problem. It seems to me that the system is lack of a C compiler while I've got a gcc compiler. I got stuck for days, any suggestions are appreciated, thanks in advance!

First question...Are you compiling software on the OpenWRT device itself!?!?

I’m not sure, pip3 install maybe need to build the package, I don’t know if there is a compiling phase involved. Maybe it does need to compile some of the .so files in the numpy package.

What?!?!

Are you using:

  • the LEDE machine; or
  • a PC

to compile this software?

Er... the LEDE machine. Why are u so surprised? pip is a commonly used tool to install dev packages in python community. I can use the exact same command to install numpy on my ubuntu 16.04. So I guess it may be related to the system development environment itself...

I'm not suprised you're using the LEDE...you weren't being clear...and you just answered me.

But...using the LEDE is likely the issue.

Why are you not using the Software Development Kit (SDK) on a PC???

I have found that pip sort-of works on the OpenWRT machine, as long as it does not require code to be compiled and as long as you aren't trying to use a venv. Without a full build chain on the OpenWRT box, you can't compile code to complete a pip install of something that has platform-specific code (which numpy does).

RuntimeError: Broken toolchain: cannot link a simple C program

I haven't been successful on getting pip to respect a venv, at least when installed from the OpenWRT build system.

You probably need more build tools, perhaps such as ld, ar, strip, nm, or the like. OpenWRT packages are minimal and often split into several parts to allow one to only install the binaries they need.

2 Likes

Well, becasue numpy is sort of a python-base package which means that most of the install logic is written by python.

From my perspective, SDK is helpful to those C/C++ base packages, like opencv, that can be built using make/cmake.

Happy to know if I'm wrong.

Em... see the word venv for the first time. Ok, I'll try that out. Thx~( ̄▽ ̄~)~

I don't know if I've got this wrong, I tried below commands:

  opkg update
  opkg install ld
  opkg install ar
  opkg install strip
  opkg install nm

only to find out I've installed ar already, and other packages are not provided.

root@LEDE:~# opkg install ld
Unknown package 'ld'.
Collected errors:
 * opkg_install_cmd: Cannot install package ld.

root@LEDE:~# opkg install ar
Package ar (2.27-1) installed in root is up to date.

root@LEDE:~# opkg install strip
Unknown package 'strip'.
Collected errors:
 * opkg_install_cmd: Cannot install package strip.

root@LEDE:~# opkg install nm
Unknown package 'nm'.
Collected errors:
 * opkg_install_cmd: Cannot install package nm.

Virtual environments are, at least for me, a great feature of modern Python. They let you keep a "clean" version on the OS, and only install the specific packages you need to run specific packages in a separate place. https://docs.python.org/3/tutorial/venv.html

I'm not sure where the remainder of the "standard" build chain is, or if it might already be installed but your PATH isn't picking them up, or your loader config isn't right, or...

opkg search <file> may help resolve some mysteries, but I believe it requires the package in question to be installed to return results.

Edit: Tried to see what I could see on my box, but it looks like gcc is 23 MB installed, before any supporting packages. You might want to consider creating a package to build this with the build system, then install the package on your device.

Ok, I'll keep trying. Thanks for the advice!

try this:
pip install Cython