Problems with pip install numpy - RuntimeError: Broken toolchain: cannot link a simple C program
Asked Answered
V

13

143

I'm trying to install numpy (and scipy and matplotlib) into a virturalenv.

I keep getting these errors though:

RuntimeError: Broken toolchain: cannot link a simple C program

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1

I have the command line tools for xcode installed

$ which gcc
/usr/bin/gcc
$ which cc
/usr/bin/cc

I'm on Mac OSX 10.9 Using a brew installed python

Edit
Yes, trying to install with pip.
The whole traceback is huge (>400 lines)

Here is a section of it:

C compiler: cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe



compile options: '-Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c'

cc: _configtest.c

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

failure.

removing: _configtest.c _configtest.o

Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/setup.py", line 192, in <module>

    setup_package()

  File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/setup.py", line 185, in setup_package

    configuration=configuration )

  File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/core.py", line 169, in setup

    return old_setup(**new_attr)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup

    dist.run_commands()

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands

    self.run_command(cmd)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command

    cmd_obj.run()

  File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/egg_info.py", line 10, in run

    self.run_command("build_src")

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command

    self.distribution.run_command(command)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command

    cmd_obj.run()

  File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/build_src.py", line 153, in run

    self.build_sources()

  File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/build_src.py", line 164, in build_sources

    self.build_library_sources(*libname_info)

  File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/build_src.py", line 299, in build_library_sources

    sources = self.generate_sources(sources, (lib_name, build_info))

  File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/build_src.py", line 386, in generate_sources

    source = func(extension, build_dir)

  File "numpy/core/setup.py", line 674, in get_mathlib_info

    raise RuntimeError("Broken toolchain: cannot link a simple C program")

RuntimeError: Broken toolchain: cannot link a simple C program
Vetchling answered 13/3, 2014 at 19:6 Comment(2)
Lol @ "cannot link a simple C program". Such sass!Solent
Get ready for a flood of newbies in 202X who naturally install python2.x in their favorite virtual environment, then do a `pip install mypackage'. Causing pip to bring you here. I think the python2 forced retirement is a bit too aggressive. A working virtual machine with python2 and pip that just works and runs legacy python written 5 and 10 years ago, will trade for many coins.Seriema
V
85

While it's ugly, it appears to work

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install --upgrade numpy

Note that if you are getting this error for a package other than numpy, (such as lxml) specify that package name instead of numpy at the end of the commnd.

I saw a similar issue someone was having with installing a gem

Ruby Gem install Json fails on Mavericks and Xcode 5.1 - unknown argument: '-multiply_definedsuppress'

This is only a temporary fix, at some point the compiler options will have to be fixed

Valueless answered 14/3, 2014 at 17:14 Comment(4)
@Ben: FWIW, I have the same issue (not using brew). It appeared after updating Xcode to 5.1. However ugly, this does appear to be the answer (for now).Gunwale
There is an explanation in the XCode 5.1 release notes.Serosa
Is unused-command-line-argument-hard-error-in-future still needed with the latest Xcode under Yosemite? Things seem to work (at least for the packages I've tired) without it.Gunwale
Anyone have a windows solution?Manzanilla
D
178

For Docker (Alpine) and Python 3.x this worked for me:

RUN apk update
RUN apk add make automake gcc g++ subversion python3-dev
Dafna answered 19/1, 2018 at 20:36 Comment(6)
For anyone using docker python3 alpine image, this is the solution.Terret
I needed an apk update first, otherwise I got a ERROR: unsatisfiable constraints message.Margit
This is also the solution for the docker python2 alpine image.Ghislainegholston
I was able to do this on alpine with only gcc g++ make python3-dev for numpy/nmslib. The cause of this particular issue seems to be the missing c++ compiler g++ (it looks by the error that gcc and make are already installed). The other important parts of numpy build is the python3 headers which come with python3-dev.Amaurosis
Not sure, if subversion is necessary. The official Python docker base on buildpack-deps where subversion is not listed.Ical
The list of packages that helped me is g++ jpeg-dev zlib-dev libjpeg make. Not sure what each of them is for.Aborigine
V
85

While it's ugly, it appears to work

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install --upgrade numpy

Note that if you are getting this error for a package other than numpy, (such as lxml) specify that package name instead of numpy at the end of the commnd.

I saw a similar issue someone was having with installing a gem

Ruby Gem install Json fails on Mavericks and Xcode 5.1 - unknown argument: '-multiply_definedsuppress'

This is only a temporary fix, at some point the compiler options will have to be fixed

Valueless answered 14/3, 2014 at 17:14 Comment(4)
@Ben: FWIW, I have the same issue (not using brew). It appeared after updating Xcode to 5.1. However ugly, this does appear to be the answer (for now).Gunwale
There is an explanation in the XCode 5.1 release notes.Serosa
Is unused-command-line-argument-hard-error-in-future still needed with the latest Xcode under Yosemite? Things seem to work (at least for the packages I've tired) without it.Gunwale
Anyone have a windows solution?Manzanilla
B
19

The problem is that you are unable to compile.

First, make sure that you have accepted the new Terms and Conditions with Xcode. To do this, just open up xCode and accept.

Then, try installing gcc with

brew install gcc

Finally, try to install Numpy with

pip install numpy

Hope this helps.

Buskirk answered 5/11, 2014 at 18:37 Comment(2)
this worked for me. Problem was I didn't open up xcode and accept terms and conditions.Resect
For those running Big Sur Beta: (1) download and install Command Line Tools for Xcode 12.2 beta 3 (2) on terminal type sudo xcode-select --switch /Library/Developer/CommandLineTools (3) brew install gcc (4) pip install numpyNarvaez
D
10

If you don't want to use sudo (so permissions and things like that are preserved when using venv), you can add the ARCHFLAGS declaration to your .bash_profile, and run as normal. This worked for me with Mavericks and Xcode 5.1 using with venv:

In ~/.bash_profile:

export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future

Then, just run the command:

pip install --upgrade numpy

Distilled answered 31/3, 2014 at 17:7 Comment(1)
the sudo above is for system-wide installation, can run without in a virtualenvPungy
T
8

If you are running a linux distribution, you may need a C compiler, especially if you see telltale log lines like sh: gcc: command not found. You can follow the instructions here, which I've summarized below:

  • Fedora, Red Hat, CentOS, or Scientific Linux

    # yum groupinstall 'Development Tools'

  • Debian or Ubuntu Linux

    $ sudo apt-get update $ sudo apt-get install build-essential manpages-dev

Then you can try rerunning:

sudo pip install numpy
Tartarus answered 2/11, 2016 at 18:46 Comment(0)
O
6

In my case this happened during a docker build. The problem was that the base image wasn't fixed to a specific python version and numpy couldn't compile with the new one.

FROM python:3-slim  # BAD

After I changed it to the following it worked:

FROM python:3.8-slim  # GOOD

Remember to fix your versions! :-)

Odericus answered 12/10, 2020 at 13:14 Comment(1)
Same thing cropped up for me today. Looks like they removed the c compiler + associated make utilities in 3.9.0.Inquisitorial
W
5

I simply had to open XCode and accept the agreement and let it install the tools. I then went back to PyCharm and installed numpy again with no issues.

Wholesome answered 29/12, 2014 at 15:29 Comment(0)
L
5

On Fedora 22 this was resolved by updating pip itself: sudo pip install --upgrade pip

Layout answered 16/12, 2016 at 14:11 Comment(1)
The same solution worked for a problem with MacOS on Big SurParaformaldehyde
H
4

For fedora users that are having a similar problem try installing these packeges:

(if not using python3 use python-devel and pip instead of pip3)

sudo dnf install python3-devel
sudo dnf install make automake gcc gcc-c++ gcc-gfortran
sudo dnf install redhat-rpm-config
sudo dnf install subversion

then try

sudo pip3 install numpy
Hearthside answered 10/5, 2016 at 17:46 Comment(0)
E
3

In some cases after OS X upgrades XCode, XCode will require the user (with administrative privileges) to accept a new license. Until the license is accepted, clang and gcc will issue an error when attempting to compile and link code. Or at least python packages.

If you launch XCode and accept the license, the errors no longer appear.

At least, this was the case for me.

Endocardial answered 21/9, 2015 at 23:1 Comment(0)
S
2

The Error:

RuntimeError: Broken toolchain: cannot link a simple C program

Means it either can't find your C compiler or encountered problems linking a simple C program.

Demo docker walkthrough, to get Python2/pip to puke that error:

Keeping this demo confined inside a read-only docker image helps us be fearless in issuing OS-wrecking root level commands and start fresh every time:

#download a read only docker image that doesn't have gcc installed:
docker pull frolvlad/alpine-python2

#check the version of pip and python:
docker run --rm frolvlad/alpine-python2 pip --version
#pip 20.3.4 from /usr/lib/python2.7/site-packages/pip (python 

Try to pip install numpy, you can't because pip needs gcc:

docker run --rm frolvlad/alpine-python2 pip install --user numpy
#...
#RuntimeError: Broken toolchain: cannot link a simple C program

gcc clearly not installed:

docker run --rm frolvlad/alpine-python2 which gcc
#empty output, gcc is not installed

So install it, now the binary /usr/bin/gcc exists:

docker run --rm frolvlad/alpine-python2 sh -c "apk update && apk add make automake gcc g++ subversion python2-dev && which gcc"
#/usr/bin/gcc

Apologies for stacking terminal commands but this is a read only image so everything has to be redone every time:

Now pip can use gcc and install numpy for python2:

docker run --rm frolvlad/alpine-python2 sh -c "apk update && apk add make automake gcc g++ subversion python2-dev && pip install numpy && python -c 'import numpy as np; print(np.__name__, np.__version__)'"
# ...
#Successfully installed numpy-1.16.6
#('numpy', '1.16.6')

We're in a good place so freeze the docker image and rename it.

docker images
#choose the most recent container id: 751420a548c1:latest and rename it:
docker commit 751420a548c1:latest frolvlad/alpine-python2_numpy

Now you have a new read only docker image with python2, pip and updated 1.16.6 numpy, ready to run your legacy python2 software like it's 2005:

docker run --rm frolvlad/alpine-python2_numpy python -c 'import numpy as np; print(np.__name__, np.__version__)'
#('numpy', '1.16.6')

Or to make the above commands simpler and sequential:

Use the -it flag on docker run which means open an interactive terminal from the docker image:

$ docker run -it frolvlad/alpine-python2_numpy sh
/ > python2 -c 'import numpy as np; print(np.__version__)'
1.16.6
/ > which gcc
/usr/bin/gcc
/ > python2 -c 'import numpy as np; print(np.zeros(3))'
[0. 0. 0.]
/ > echo "headward free now to rise"; exit;

As python2 packages fall further into ancient history, pip will have to be configured to point at your a private python2 package repository url.

Seriema answered 11/11, 2022 at 20:5 Comment(0)
U
0

I solved this by using Conda instead of pip in my Dockerfile: FROM continuumio/miniconda3:latest

Unmixed answered 20/4, 2021 at 8:28 Comment(0)
A
-1

Old thread, by my problem was that I didn't have Xcode installed. The following solved it.

xcode-select --install
Adrianneadriano answered 12/5, 2021 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.