clang 错误:未知参数:'-mno-fused-madd'(python 包安装失败)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22313407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
clang error: unknown argument: '-mno-fused-madd' (python package installation failure)
提问by tino
I get the following error when attempting to install psycopg2via pip on Mavericks 10.9:
尝试psycopg2在 Mavericks 10.9 上通过 pip安装时出现以下错误:
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 的完整输出:
$ 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
采纳答案by user3405578
You can tell clang to not raise this as an error by setting the following environment variables prior compilation:
您可以通过在编译之前设置以下环境变量来告诉 clang 不要将此作为错误引发:
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
Then pip install psycopg2should work.
然后pip install psycopg2应该工作。
I had the same when trying to pip install lxml.
我在尝试时也有同样的情况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:
编辑:如果您以超级用户身份安装(如果您尝试附加到/Library/Python/2.7/site-packagesOS X 附带的本机 Apple 工厂安装的 Python 发行版,而不是您随后自己安装的其他一些 Python 发行版,则可能会出现这种情况)),那么您将需要执行以下操作,如@Thijs Kuipers 在下面的评论中所述:
sudo -E pip install psycopg2
or the equivalent, for whatever other package name you may be substituting in place of psycopg2.
或等效的,对于您可能替换的任何其他包名称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.3so 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.
更新 [2014-05-16]:Apple 已通过更新的系统 Python(2.7、2.6 和 2.5)修复了此问题,OS X 10.9.3因此在使用最新的 Mavericks 和Xcode 5.1+. 但是,截至目前,OS X 10.8.x如果您在Xcode 5.1+那里使用(Mountain Lion,目前为 10.8.5),仍然需要解决方法。
回答by Paul Kehrer
Update: 10.9.3 resolves the issue with system CPython.
更新:10.9.3 解决了系统 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.
这是由今天 Xcode 5.1 附带的 Apple 最新的 clang 更新引起的,并且影响了很多很多人,因此希望很快就会出现修复程序。
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:
更新:没想到这会引起如此多的关注,但这里有更多细节: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
To resolve this issue you have a few options:
要解决此问题,您有几个选择:
- Add
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-futureto 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.
- 添加
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future到您的编译标志。 - 经过
CFLAGS="" - 从 sysconfigdata.py 中删除不受支持的标志(如另一个答案中所述)。
- 使用homebrew编译一个新的 python 。
- 等待下一个 OS X 更新,据传它包含重新编译的 Python/Ruby,以消除系统运行时的这个问题。
回答by user3405479
Here is a work around that involves removing the flag from the python installation.
这是一个解决方法,涉及从 python 安装中删除标志。
In /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.pyare several places where the -mfused-madd/ -mno-fused-maddflag is set.
在/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py几个地方设置了-mfused-madd/-mno-fused-madd标志。
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.pycand _sysconfigdata.pyofiles as well - at least on my system these files did not automatically get rebuilt:
您还需要删除相应的_sysconfigdata.pyc和_sysconfigdata.pyo文件 - 至少在我的系统上,这些文件没有自动重建:
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.
请注意,必须使用 root 访问权限才能进行这些更改。
回答by Vitaliy Khamin
回答by Isis
xCode 5.1
代码 5.1
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install psycopg2
回答by Ben
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.
我还编辑了系统 python 对其原始编译标志的概念(如@user3405479 所做的那样)。我没有使用编辑器,而是使用命令行工具“就地”编辑文件(inode 确实发生了变化)。我还编译了新的 pyo 和 pyc 文件,而不是将它们删除。
The following commands are run as root, for example under sudo -i
以下命令以 root 身份运行,例如在 sudo -i
pushd /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
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
sed 's/-mno-fused-madd//g' _sysconfigdata.py \
| diff -p _sysconfigdata.py - | patch -b
python -m py_compile _sysconfigdata.py
python -m py_compile _sysconfigdata.py
python -OO -m py_compile _sysconfigdata.py
python -OO -m py_compile _sysconfigdata.py
popd
popd
回答by Nathan
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:
我用homebrew安装了postgresql,然后想把psycopg2安装到系统自带的python 2.7上小牛。为了让它工作,我最终运行了这个:
sudo ARCHFLAGS="-arch x86_64" CFLAGS=-Wunused-command-line-argument-hard-error-in-future pip install psycopg2
回答by Hans Wolkenkratzer
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.
以上解决方案都不适合我。我的情况略有不同。当我收到此错误消息时,我试图通过自制软件安装 rdiff-backup。
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.
我显然有 Apple 的默认 python (2.7.5 @ /usr/bin/python) 和 Homebrew 的 python (2.7.6 @ /usr/local/Cellar/python/2.7.6/bin/python),但错误来了来自苹果的蟒蛇。
To fix the problem, basically I switched the python binaries.
为了解决这个问题,基本上我切换了 python 二进制文件。
I did this via sudo:
我是通过 sudo 做到的:
- cp /usr/bin/python /usr/bin/python_orig
- ln -s /usr/local/Cellar/python/2.7.6/bin/python /usr/bin/python
- 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.
然后,'brew install rdiff-backup' 成功而没有任何错误。
Finally, I did "mv /usr/bin/python_orig /usr/bin/python" to revert everything back.
最后,我做了“mv /usr/bin/python_orig /usr/bin/python”来恢复一切。
回答by bolson
Variation on the _sysconfigdata.py fix: use a virtual environment
_sysconfigdata.py 修复的变化:使用虚拟环境
cp /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py ${VIRTUAL_ENV}/lib/python2.7/_sysconfigdata.py
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
然后在 ${VIRTUAL_ENV}/lib/python2.7/_sysconfigdata.py 编辑您的副本
I removed all the occurences of '-mno-fused-madd' and then builds worked in that virtualenv.
我删除了'-mno-fused-madd'的所有出现,然后在那个virtualenv中构建工作。
No root needed!
无需root!
回答by llude
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-futureflag is meant to be a temporary workaround and will go away in the future (hopefully after system Python is fixed!).
至少 Apple 意识到了这一点,因为在 Xcode 5.1发行说明(编译器部分)中讨论了这个问题。期待在下一次操作系统更新中更新 Python 和 Ruby(手指交叉!)。另请注意,该-Wno-error=unused-command-line-argument-hard-error-in-future标志是一种临时解决方法,将来会消失(希望在系统 Python 修复后!)。
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.pyfile:
如果您是像我一样的 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},
...
)

