275

I get the following error when attempting to install psycopg2 via pip on Mavericks 10.9:

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

Not sure how to proceed and have searched here and elsewhere for this particular error. Any help is much appreciated!

Here is the complete output from pip:

$ pip install psycopg2
Downloading/unpacking psycopg2
  Downloading psycopg2-2.5.2.tar.gz (685kB): 685kB downloaded
  Running setup.py (path:/private/var/folders/0z/ljjwsjmn4v9_zwm81vhxj69m0000gn/T/pip_build_tino/psycopg2/setup.py) egg_info for package psycopg2

Installing collected packages: psycopg2
  Running setup.py install for psycopg2
    building 'psycopg2._psycopg' extension
    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 -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090303 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I. -I/usr/local/Cellar/postgresql/9.3.3/include -I/usr/local/Cellar/postgresql/9.3.3/include/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.9-intel-2.7/psycopg/psycopgmodule.o
    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
    error: command 'cc' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/0z/ljjwsjmn4v9_zwm81vhxj69m0000gn/T/pip_build_tino/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/0z/ljjwsjmn4v9_zwm81vhxj69m0000gn/T/pip-bnWiwB-record/install-record.txt --single-version-externally-managed --compile:
    running install

running build

running build_py

creating build

creating build/lib.macosx-10.9-intel-2.7

creating build/lib.macosx-10.9-intel-2.7/psycopg2

copying lib/__init__.py -> build/lib.macosx-10.9-intel-2.7/psycopg2

copying lib/_json.py -> build/lib.macosx-10.9-intel-2.7/psycopg2

copying lib/_range.py -> build/lib.macosx-10.9-intel-2.7/psycopg2

copying lib/errorcodes.py -> build/lib.macosx-10.9-intel-2.7/psycopg2

copying lib/extensions.py -> build/lib.macosx-10.9-intel-2.7/psycopg2

copying lib/extras.py -> build/lib.macosx-10.9-intel-2.7/psycopg2

copying lib/pool.py -> build/lib.macosx-10.9-intel-2.7/psycopg2

copying lib/psycopg1.py -> build/lib.macosx-10.9-intel-2.7/psycopg2

copying lib/tz.py -> build/lib.macosx-10.9-intel-2.7/psycopg2

creating build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/__init__.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/dbapi20.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/dbapi20_tpc.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_async.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_bug_gc.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_bugX000.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_cancel.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_connection.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_copy.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_cursor.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_dates.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_extras_dictcursor.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_green.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_lobject.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_module.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_notify.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_psycopg2_dbapi20.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_quote.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_transaction.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_types_basic.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_types_extras.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/test_with.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/testconfig.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

copying tests/testutils.py -> build/lib.macosx-10.9-intel-2.7/psycopg2/tests

running build_ext

building 'psycopg2._psycopg' extension

creating build/temp.macosx-10.9-intel-2.7

creating build/temp.macosx-10.9-intel-2.7/psycopg

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 -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090303 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I. -I/usr/local/Cellar/postgresql/9.3.3/include -I/usr/local/Cellar/postgresql/9.3.3/include/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.9-intel-2.7/psycopg/psycopgmodule.o

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

error: command 'cc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/0z/ljjwsjmn4v9_zwm81vhxj69m0000gn/T/pip_build_tino/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/0z/ljjwsjmn4v9_zwm81vhxj69m0000gn/T/pip-bnWiwB-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/var/folders/0z/ljjwsjmn4v9_zwm81vhxj69m0000gn/T/pip_build_tino/psycopg2
al45tair
  • 4,405
  • 23
  • 30
tino
  • 4,780
  • 5
  • 24
  • 30

15 Answers15

441

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.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
user3405578
  • 4,434
  • 1
  • 11
  • 2
  • 2
    I had this problem installing `greenlet` with pip. This fixed it, thanks. – jbrown Mar 11 '14 at 14:21
  • 1
    This worked for me as an immediate fix, thanks! See Paul Kehrer's answer for an explanation as to the source of the problem. – tino Mar 11 '14 at 17:02
  • I get the same error even after setting these environment variables. – Mihai Damian Mar 11 '14 at 20:42
  • sorry -- new guy here -- where does this go? – Sean Danzeiser Mar 11 '14 at 21:03
  • @SeanDanzeiser: enter those two `export` commands directly into your shell. – tino Mar 11 '14 at 22:30
  • @tino hmm i stuck that in my .bashrc and i am still getting the same error – Sean Danzeiser Mar 11 '14 at 23:21
  • @SeanDanzeiser did you reload your shell session? profile changes don't take effect until your profile is reloaded. Or, instead, just try typing those commands directly at the prompt rather than permanently adding them to .bashrc. I'm guessing a better permanent fix is forthcoming. – tino Mar 12 '14 at 00:00
  • Thanks a lot! This helped me with lxml and psycopg2. For lxml, I also had to reinstall libxml2 and libxslt with brew following vicchis hint at https://github.com/Homebrew/homebrew/issues/27464. – aldi Mar 12 '14 at 13:50
  • This worked perfectly. I assume that this is no coincidence that this started happening after the last upgrade of Xcode. – juice Mar 17 '14 at 17:29
  • 5
    If you install as root you need to set the flags for the root user. – ErikAndren Mar 18 '14 at 06:29
  • 48
    I had to add the `-E` flag to `sudo` to load the environment variables for root execution like @ErikAndren said. So first the two abovementioned `export` statements, followed by `sudo -E doSomething`. – Thijs Kuipers Mar 18 '14 at 22:43
  • This resolved a similar issue with `pip install pandas`. – Matt Faus Mar 24 '14 at 21:56
  • This also resolves the issue when installing `cython`. – tamasgal Mar 25 '14 at 14:36
  • This helped me to install iPython in a virtualenv with gnu readline. Thank you very much! – Rolandf Apr 11 '14 at 21:59
  • 1
    Awesome. This should be included in Python guide for OS X 10.9 users. – Kenial Apr 16 '14 at 19:01
  • Supressing errors -- this is really the eternal Python-way. – Nakilon Apr 24 '14 at 11:02
  • Note, this is not a bug in Python; it is a bug introduced by Apple by using a non-standard build configuration for Python and then changing compiler defaults in Xcode 5.1 without thoroughly testing their impact. Apple has fixed the problem in OS X 10.9.3. – Ned Deily May 16 '14 at 18:58
  • I still had to use this work-a-round on Mavericks (OSX 10.9.2). – b01 Jun 10 '14 at 20:16
  • Tried this on Mountain Lion and got past the '-mno-fused-madd', but installation now fails with error: ld: library not found for -lssl clang: error: linker command failed with exit code 1. – user1255933 Jun 13 '14 at 22:38
  • Just want to tag this ansible since it solved my installation problem there - cheers – starsinmypockets Aug 30 '15 at 15:31
  • 10.8.5 Mountan Lion and was doing the Heroku install for python - this did the trick - thanks all – MplsRich May 13 '17 at 02:44
76

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.
Paul Kehrer
  • 13,466
  • 4
  • 40
  • 57
  • @paul, ah thanks for the info. is there a way to stay up to date on the status of this bug that you're aware of? i'd love to update clang as soon as a fix is available. – tino Mar 11 '14 at 16:18
  • 2
    That is not a clang bug, that is a distribution bug of Apple. Apple should not distribute a Python version that has been built with settings incompatible to clang 3.4. It is properly fixed by Apple updating the Python interpreter. – Till Mar 11 '14 at 18:56
  • You can validate this by running `python-config --cflags`. When being run on Apple's default Python, it will show options unknown to clang 3.4. – Till Mar 11 '14 at 18:58
  • is there a solution to this if I've already updated to Xcode 5.1? Adding those exports into bashrc as proposed above didn't seem to resolve the issue. – Sean Danzeiser Mar 11 '14 at 23:30
  • To Sean: On my Mac I have ``~/.bash_profile`` not bashrc, but this would need you to restart the shell to take effect. – Peter Cock Mar 12 '14 at 10:00
  • wish I could up vote this all again. I couldn't get past the error using the CFLAGS but adjusting the sysconfigdata.py did the trick! – Sean Danzeiser Mar 12 '14 at 18:34
  • Had the same problem with a ruby gem. Using info from http://stackoverflow.com/questions/22352838/ruby-gem-install-json-fails-on-mavericks-and-xcode-5-1-unknown-argument-mul and then sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future buildcommandhere did the trick. – stephenhouser Mar 13 '14 at 01:22
63

xCode 5.1

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install psycopg2
Isis
  • 4,608
  • 12
  • 39
  • 61
15

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.

James
  • 24,676
  • 13
  • 84
  • 130
user3405479
  • 151
  • 2
4

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

Ron
  • 254
  • 2
  • 17
Ben
  • 145
  • 1
  • 5
4

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
Nathan Stocks
  • 2,096
  • 3
  • 20
  • 31
2

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},
    ...
)
llude
  • 1,173
  • 8
  • 10
1

None of the above solutions worked for me. My situation is slightly different. I was trying to install rdiff-backup via homebrew when I got this error message.

I apparently have both Apple's default python (2.7.5 @ /usr/bin/python) and Homebrew's python (2.7.6 @ /usr/local/Cellar/python/2.7.6/bin/python), but the error was coming from Apple's python.

To fix the problem, basically I switched the python binaries.

I did this via sudo:

  • cp /usr/bin/python /usr/bin/python_orig
  • ln -s /usr/local/Cellar/python/2.7.6/bin/python /usr/bin/python

Then, 'brew install rdiff-backup' succeeded without any errors.

Finally, I did "mv /usr/bin/python_orig /usr/bin/python" to revert everything back.

1

You're probably on Python 2.7.5

$ python

Python 2.7.5 (default, Aug 25 2013, 00:04:04)  [GCC 4.2.1 Compatible
Apple LLVM 5.0 (clang-500.0.68)] on darwin

Easiest solution go to www.python.org and install Python 2.7.6 which is compatible with the LLVM 5.1.

Then toast your old virtual environment, rmvirtualenv {virtual_env_name}.

Then make a new virtual env..

mkvirtualenv --no-site-packages -p/Library/Frameworks/Python.framework/Versions/2.7/bin/python {virtual_env_name}

pip should work fine after this.

taskinoor
  • 45,586
  • 12
  • 116
  • 142
affablebloke
  • 457
  • 4
  • 14
1

Amazon Linux [AWS EC2]

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
stevec
  • 41,291
  • 27
  • 223
  • 311
Bruno Bronosky
  • 66,273
  • 12
  • 162
  • 149
0

I used homebrew python package. Works well after re-compilling.

0

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!

Nathan Fisher
  • 7,961
  • 3
  • 47
  • 68
bolson
  • 44
  • 2
0

For me, the bad flags were explicitly given in the package's Makefile. So I had to edit the makefile to remove the unrecognized flag from the erroring package.

mike
  • 1
0

Upgrading Homebrew and installing unixodbc solved it for me

brew upgrade
brew install unixodbc
Vipassana Vijayarangan
  • 8,799
  • 2
  • 17
  • 20
0

im here after failing builds on a mac with M2

and the solution was adding to ~/.zshrc

# Since M2
export DOCKER_DEFAULT_PLATFORM=linux/amd64