在Mavericks 10.9上试图通过pip安装psycopg2时,我得到以下错误:

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

不知道如何继续,已经在这里和其他地方搜索了这个特定的错误。任何帮助都非常感激!

以下是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

当前回答

你可以通过在编译之前设置以下环境变量来告诉clang不要引发这个错误:

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

然后pip安装psycopg2应该工作。

当我试图pip安装lxml时,我有同样的问题。

编辑:如果你以超级用户身份安装(如果你试图添加到/Library/Python/2.7/site-packages,苹果工厂安装的Python发行版,而不是你随后自己安装的其他Python发行版,则很可能会出现这种情况),那么你将需要这样做,正如@Thijs Kuipers在评论中所描述的那样:

sudo -E pip install psycopg2

或者等效的,对于任何您可能替换psycopg2的其他包名。

更新[2014-05-16]:苹果已经在OS X 10.9.3的更新系统python(2.7、2.6和2.5)中修复了这个问题,因此在使用最新的Mavericks和Xcode 5.1+时不再需要这个变通方法。然而,到目前为止,OS X 10.8仍然需要这个解决方案。x (Mountain Lion,目前10.8.5),如果你使用的是Xcode 5.1+。

其他回答

至少苹果意识到了这个问题,因为这个问题在Xcode 5.1发布说明(编译器部分)中有讨论。期待在下一次操作系统更新中更新Python和Ruby(祈祷吧!)还要注意-Wno-error=unused-command-line-argument-hard-error-in-future标志是一个临时的解决方案,将来会消失(希望在系统Python修复之后!)

如果你像我一样是一个Python包维护者,并且想为你的用户省去自己处理这些问题的麻烦,这里有一个解决方案(除了提供二进制轮/卵),它会放在你的setup.py文件中:

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},
    ...
)

我还编辑了系统python的原始编译标志的概念(正如@user3405479所做的那样)。我没有使用编辑器,而是使用命令行工具“就地”编辑文件(inode会发生变化)。我还编译了新的pyo和pyc文件,而不是删除它们。

以下命令以root用户运行,例如在sudo -i下运行

pushd /系统/图书馆/框架/ Python.framework /版本/ 2.7 / lib / python2.7

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

Python -m py_compile _sysconfigdata.py

python -OO -m py_compile _sysconfigdata.py

popd

以上的方法对我来说都没用。我的情况略有不同。当我收到这个错误消息时,我正试图通过自制程序安装rdiff-backup。

我显然有苹果的默认python (2.7.5 @ /usr/bin/python)和Homebrew的python (2.7.6 @ /usr/local/Cellar/python/2.7.6/bin/python),但错误来自苹果的python。

为了解决这个问题,我基本上切换了python二进制文件。

我通过sudo做到了这一点:

cp /usr/蟒蛇/usr/bin/python_orig -在s /usr/local/Cellar/python/2.7.6/bin/python /usr/ python

然后,'brew install rdiff-backup'成功,没有任何错误。

最后,我执行“mv /usr/bin/python_orig /usr/bin/python”来还原所有内容。

_sysconfigdata.py修复的变体:使用虚拟环境

cp /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py ${VIRTUAL_ENV}/lib/python2.7/_sysconfigdata.py

然后编辑你的拷贝到${VIRTUAL_ENV}/lib/python2.7/_sysconfigdata.py

我删除了'-mno-fused-madd'的所有出现,然后构建在那个virtualenv中工作。

不需要根!

你可能使用的是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

最简单的解决方案是去www.python.org并安装与LLVM 5.1兼容的Python 2.7.6。

然后吐司您的旧虚拟环境rmvirtualenv {virtual_env_name}。

然后创建一个新的虚拟环境。

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

在此之后PIP应该可以正常工作。