I get the following error when attempting to install psycopg2
via pip on Mavericks 10.9:
clang: error: unknown argument: \'-mno-fused-madd\' [-W
xCode 5.1
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install psycopg2
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
At least Apple is aware of this as this issue is discussed in the Xcode 5.1 Release Notes (Compiler section). Expect an updated Python and Ruby in the next OS update (fingers crossed!). Also take note that the -Wno-error=unused-command-line-argument-hard-error-in-future
flag is meant to be a temporary workaround and will go away in the future (hopefully after system Python is fixed!).
If you are a Python package maintainer like me and want to save your users the hassle of working around this themselves, here is a solution (besides providing binary wheels/eggs) that goes into your setup.py
file:
from distutils.command.build_ext import build_ext
import subprocess
import sys
# Workaround for OS X 10.9.2 and Xcode 5.1+
# The latest clang treats unrecognized command-line options as errors and the
# Python CFLAGS variable contains unrecognized ones (e.g. -mno-fused-madd).
# See Xcode 5.1 Release Notes (Compiler section) and
# http://stackoverflow.com/questions/22313407 for more details. This workaround
# follows the approach suggested in http://stackoverflow.com/questions/724664.
class build_ext_subclass(build_ext):
def build_extensions(self):
if sys.platform == 'darwin':
# Test the compiler that will actually be used to see if it likes flags
proc = subprocess.Popen(self.compiler.compiler + ['-v'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
stdout, stderr = proc.communicate()
clang_mesg = "clang: error: unknown argument: '-mno-fused-madd'"
if proc.returncode and stderr.splitlines()[0].startswith(clang_mesg):
for ext in self.extensions:
# Use temporary workaround to ignore invalid compiler option
# Hopefully -mno-fused-madd goes away before this workaround!
ext.extra_compile_args += ['-Wno-error=unused-command-line-argument-hard-error-in-future']
build_ext.build_extensions(self)
setup(
name="mypackage",
...
cmdclass={'build_ext' : build_ext_subclass},
...
)
Variation on the _sysconfigdata.py fix: use a virtual environment
cp /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py ${VIRTUAL_ENV}/lib/python2.7/_sysconfigdata.py
Then edit your copy at ${VIRTUAL_ENV}/lib/python2.7/_sysconfigdata.py
I removed all the occurences of '-mno-fused-madd' and then builds worked in that virtualenv.
No root needed!
Trying to pip install paramiko
on Amazon Linux AMI release 2016.09
gave me an error that included a link to this SO post. So, even though it doesn't fit the OP's Title, I'm going to share the answer.
yum install libffi-devel
yum install gcc
yum install openssl-devel
pip install paramiko
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