Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang error: unknown argument: '-mno-fused-madd' (python package installation failure)

You can tell clang to not raise this as an error by setting the following environment variables prior compilation:

export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments

Then pip install psycopg2should work.

I had the same when trying to pip install lxml.

Edit: if you are installing as superuser (which will likely be the case if you are trying to append to /Library/Python/2.7/site-packages, the native Apple factory-installed Python distribution which ships with OS X, rather than to some other Python distribution which you have subsequently installed yourself), then you will need to do, as described by @Thijs Kuipers in comments below:

sudo -E pip install psycopg2

or the equivalent, for whatever other package name you may be substituting in place of psycopg2.

UPDATE [2014-05-16]: Apple has fixed this problem with updated system Pythons (2.7, 2.6, and 2.5) in OS X 10.9.3 so the workaround is no longer necessary when using the latest Mavericks and Xcode 5.1+. However, as of now, the workaround is still required for OS X 10.8.x (Mountain Lion, currently 10.8.5) if you are using Xcode 5.1+ there.


Update: 10.9.3 resolves the issue with system CPython.

This is caused by the latest clang update from Apple that came with Xcode 5.1 today and is affecting many, many people, so hopefully a fix will appear soon.

Update: Did not expect this to get so much attention, but here's more detail: the clang 3.4 Apple is shipping defaults to erroring on unknown flags, but CPython builds modules using the same set of flags it was compiled with originally. The system CPython was compiled with several flags that are unknown by clang, thus causing this problem. The following are the current Mavericks (10.9.2) CPython compile flags:

-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -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

To resolve this issue you have a few options:

  • Add ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future to your compile flags.
  • Pass CFLAGS=""
  • Strip the unsupported flags from the sysconfigdata.py (as is noted in another answer).
  • Compile a new python using homebrew.
  • Wait for the next OS X update, which is rumored to include recompiled Python/Ruby to remove this issue for system runtimes.

xCode 5.1

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install psycopg2

Here is a work around that involves removing the flag from the python installation.

In /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py are several places where the -mfused-madd / -mno-fused-madd flag is set.

Edit this file and remove all of the references to that flag your compilation should work:

sudo sed -i '.old' 's/ -m\(no-\)\{0,1\}fused-madd //g' /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py

You need to delete the corresponding _sysconfigdata.pyc and _sysconfigdata.pyo files as well - at least on my system these files did not automatically get rebuilt:

cd /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
sudo rm _sysconfigdata.pyo _sysconfigdata.pyc

Note that have to use root access to make those changes.


I also edited the system python's notion of its original compile flags (as @user3405479 did). Instead of an editor I used command line tools to edit the file "in place" (the inode does change). I also compiled new pyo and pyc files instead of leaving them deleted.

The following commands are run as root, for example under sudo -i

pushd /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7

sed 's/-mno-fused-madd//g' _sysconfigdata.py \ | diff -p _sysconfigdata.py - | patch -b

python -m py_compile _sysconfigdata.py

python -OO -m py_compile _sysconfigdata.py

popd


I used homebrew to install postgresql, and then wanted to install psycopg2 into the system-provided python 2.7 on Mavericks. To get that to work I ended up running this:

sudo ARCHFLAGS="-arch x86_64" CFLAGS=-Wunused-command-line-argument-hard-error-in-future pip install psycopg2