【问题标题】:clang error: unknown argument: '-mno-fused-madd' (python package installation failure)clang 错误:未知参数:'-mno-fused-madd'(python 包安装失败)
【发布时间】:2014-04-14 08:06:24
【问题描述】:

在 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

【问题讨论】:

  • 我在构建 C 库时遇到同样的错误:clang: error: unknown argument: '-mno-fused-madd'...
  • 任何包含 C 模块的 Python 包都会出现此问题,而不仅仅是 psycopg2。

标签: python clang pip osx-mavericks


【解决方案1】:

您可以通过在编译前设置以下环境变量来告诉 clang 不要将此作为错误提出:

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

那么pip install psycopg2应该可以工作。

我在尝试pip install lxml 时遇到了同样的情况。

编辑:如果您以超级用户身份安装(如果您尝试附加到/Library/Python/2.7/site-packages,可能会出现这种情况,这是 OS X 附带的原生 Apple 工厂安装的 Python 发行版,而不是其他一些 Python 发行版您随后自己安装了),那么您将需要按照以下 cmets 中的@Thijs Kuipers 所述进行操作:

sudo -E pip install psycopg2

或同等名称,您可以用其他包名称代替psycopg2

更新 [2014-05-16]:Apple 已在 OS X 10.9.3 中通过更新的系统 Python(2.7、2.6 和 2.5)修复了此问题,因此在使用最新的 Mavericks 和 Xcode 5.1+ 时不再需要解决方法。但是,到目前为止,如果您在那里使用Xcode 5.1+OS X 10.8.x(Mountain Lion,当前为 10.8.5)仍然需要解决方法。

【讨论】:

  • 我在使用 pip 安装 greenlet 时遇到了这个问题。这解决了它,谢谢。
  • 这对我来说是一个即时修复,谢谢!有关问题根源的解释,请参见 Paul Kehrer 的回答。
  • 如果您以 root 身份安装,则需要为 root 用户设置标志。
  • 我必须将-E 标志添加到sudo 才能像@ErikAndren 所说的那样加载root 执行的环境变量。所以首先是上面提到的两个export 语句,然后是sudo -E doSomething
  • 用枕头救了我的命。谢谢!
【解决方案2】:

更新:10.9.3 解决了系统 CPython 的问题。

这是由今天 Xcode 5.1 附带的 Apple 最新的 clang 更新引起的,并且影响了很多很多人,因此希望很快会出现修复。

更新:没想到这会引起如此多的关注,但这里有更多细节:clang 3.4 Apple 将默认设置为在未知标志上出错,但 CPython 使用与最初编译时相同的一组标志来构建模块。系统 CPython 编译时使用了许多 clang 未知的标志,因此导致了这个问题。以下是当前 Mavericks (10.9.2) CPython 编译标志:

-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

要解决此问题,您有几个选择:

  • ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future 添加到您的编译标志中。
  • 通过CFLAGS=""
  • 从 sysconfigdata.py 中删除不受支持的标志(如另一个答案中所述)。
  • 使用homebrew编译一个新的python。
  • 等待下一次 OS X 更新,传闻将包含重新编译的 Python/Ruby 以消除系统运行时的这个问题。

【讨论】:

  • @paul,谢谢你的信息。有没有办法及时了解您知道的这个错误的状态?一旦有可用的修复程序,我很想更新 clang。
  • 这不是clang的bug,是苹果的发行版bug。 Apple 不应分发使用与 clang 3.4 不兼容的设置构建的 Python 版本。 Apple 更新 Python 解释器已正确修复它。
  • 您可以通过运行python-config --cflags 来验证这一点。在 Apple 的默认 Python 上运行时,它将显示 clang 3.4 未知的选项。
  • 如果我已经更新到 Xcode 5.1,是否有解决方案?按照上面的建议将这些导出添加到 bashrc 似乎并没有解决问题。
  • 致 Sean:在我的 Mac 上我有 ~/.bash_profile 而不是 bashrc,但这需要你重新启动 shell 才能生效。
【解决方案3】:

xCode 5.1

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

【讨论】:

  • 太好了,帮我装枕头
  • 我在通过 pip 安装 psycog2 时遇到了很多问题,这解决了我的问题。非常感谢。
  • 如果你使用sudo,在设置环境变量之前需要先sudo。 (即sudo ARCHFLAGS=... pip install ...
  • 用于安装 pycrypto。谢谢!
【解决方案4】:

这是一个涉及从 python 安装中删除标志的解决方法。

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py 中有几个位置设置了-mfused-madd / -mno-fused-madd 标志。

编辑此文件并删除对该标志的所有引用,您的编译应该可以工作:

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

您还需要删除相应的 _sysconfigdata.pyc_sysconfigdata.pyo 文件 - 至少在我的系统上这些文件没有自动重建:

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

请注意,必须使用 root 访问权限才能进行这些更改。

【讨论】:

  • 这确实有效!我不得不同时删除 _sysconfigdata.pyc 和 _sysconfigdata.pyo
【解决方案5】:

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

以下命令以root身份运行,例如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

【讨论】:

  • 在 Apple 修复其 Python 安装之前,这似乎是最实用和最权威的解决方案。感谢您提供完整的说明!
【解决方案6】:

我使用 homebrew 安装 postgresql,然后想将 psycopg2 安装到 Mavericks 上系统提供的 python 2.7 中。为了让它工作,我最终运行了这个:

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

【讨论】:

    【解决方案7】:

    至少 Apple 意识到了这一点,因为此问题已在 Xcode 5.1 Release Notes(编译器部分)中讨论。期待在下一次操作系统更新中更新 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},
        ...
    )
    

    【讨论】:

      【解决方案8】:

      以上解决方案都不适合我。我的情况略有不同。当我收到此错误消息时,我正在尝试通过自制软件安装 rdiff-backup。

      我显然同时拥有 Apple 的默认 python (2.7.5 @ /usr/bin/python) 和 Homebrew 的 python (2.7.6 @ /usr/local/Cellar/python/2.7.6/bin/python),但是错误来自 Apple 的 python。

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

      我是通过 sudo 完成的:

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

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

      最后,我执行了“mv /usr/bin/python_orig /usr/bin/python”来恢复一切。

      【讨论】:

        【解决方案9】:

        您可能使用的是 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 在此之后应该可以正常工作。

        【讨论】:

        • 可能想在烘烤之前从旧环境中提取需求;) pip freeze > requirements.txt
        【解决方案10】:

        亚马逊 Linux [AWS EC2]

        Amazon Linux AMI release 2016.09 上尝试pip install paramiko 时出现错误,其中包含指向此 SO 帖子的链接。所以,即使它不符合 OP 的标题,我也会分享答案。

        yum install libffi-devel
        yum install gcc
        yum install openssl-devel
        pip install paramiko
        

        【讨论】:

          【解决方案11】:

          我使用了homebrew python 包。 重新编译后运行良好。

          【讨论】:

            【解决方案12】:

            _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 中工作。

            无需root!

            【讨论】:

              【解决方案13】:

              对我来说,错误标志是在包的 Makefile 中明确给出的。所以我不得不编辑 makefile 以从错误包中删除无法识别的标志。

              【讨论】:

                【解决方案14】:

                升级 Homebrew 并安装 unixodbc 为我解决了这个问题

                brew upgrade
                brew install unixodbc
                

                【讨论】:

                  猜你喜欢
                  • 2014-04-18
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2014-05-07
                  • 2014-11-24
                  • 1970-01-01
                  • 2014-05-26
                  相关资源
                  最近更新 更多