安装pandas时出现问题:“命令'llvm-gcc-4.2'失败,退出状态为1”

4
我想在MAC OS X 10.7上用Python 2.7安装pandas,命令为“sudo pip install pandas”。我得到了一些输出: ```` ``` ```
Frameworks/Python.framework/Versions/2.7/include/python2.7 -c pandas/index.c -o build/temp.macosx-10.7-intel-2.7/pandas/index.o
    In file included from pandas/index.c:317:
    pandas/src/numpy_helper.h: In function ‘infer_type’:
    pandas/src/numpy_helper.h:32: error: ‘PyDatetimeArrType_Type’ undeclared (first use in this function)
    pandas/src/numpy_helper.h:32: error: (Each undeclared identifier is reported only once
    pandas/src/numpy_helper.h:32: error: for each function it appears in.)
    pandas/src/numpy_helper.h: In function ‘get_datetime64_value’:
    pandas/src/numpy_helper.h:53: error: ‘PyDatetimeScalarObject’ undeclared (first use in this function)
    pandas/src/numpy_helper.h:53: error: expected expression before ‘)’ token
    pandas/src/numpy_helper.h: In function ‘is_datetime64_object’:
    pandas/src/numpy_helper.h:84: error: ‘PyDatetimeArrType_Type’ undeclared (first use in this function)
    pandas/src/numpy_helper.h: In function ‘is_timedelta64_object’:
    pandas/src/numpy_helper.h:89: error: ‘PyTimedeltaArrType_Type’ undeclared (first use in this function) 

我得到了这个:
lipo: can't open input file: /var/tmp//ccaW8SVp.out (No such file or directory)

error: command 'llvm-gcc-4.2' failed with exit status 1

所有依赖项(NumPy、pythondateutil、pytz)都运行良好。我也按照这里建议的安装了最新版本的命令行工具:为什么会出现“command 'llvm-gcc-4.2' failed with exit status 1”错误?和这里:gcc-4.2失败,退出状态为1 我认为我的问题与这个(没有帮助的)帖子密切相关:在MAC中安装Python中的Pandas时出现问题 现在我没有其他选择,真的不知道该怎么办:-( 除了请求帮助......因此提前感谢!

1
你是如何尝试构建/安装Pandas的?你下载了源代码,使用了pip、Homebrew、MacPorts等吗? - MattDMo
哦,这太快了。我正在使用“sudo pip install pandas”。我编辑了问题。 - los_floppos
你使用的是哪个版本的Python?你是从python.org安装的还是使用默认的系统版本? - MattDMo
我建议您使用conda来安装pandas/scipy/sklearn。这样您就不必处理构建C扩展的问题了。 - TomAugspurger
@MattDMo 这是Python 2.7版本。我使用了从这里获取的版本:http://www.python.org/download/ - los_floppos
如果你在命令行中运行 head -1 \which pip`,它会返回什么?可能是 pip` 正在使用系统 Python 而不是 python.org 版本。 - MattDMo
4个回答

6
对我来说,以下方法解决了这个问题:
sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/
sudo pip install --upgrade numpy
sudo pip install pandas

我注意到Pandas正在尝试链接旧版本的numpy,位于Frameworks下面,而不是新版本的numpy,位于/Library/Python/2.7/site-packages


1
安装需要一点时间,但我发现 MacPorts 在安装第三方模块方面非常有用。在我的经验中,它比 Homebrew 有更多的可用包,并且依赖关系的安装比自己尝试要简单得多。查看 Quick Start 以了解安装方法。
安装完成后,请重新启动终端会话,并检查您的 PATHecho $PATH)以确保 /opt/local/bin/usr/bin/Library/Frameworks/Python.framework/Versions/2.7/bin 之前。然后,您可以运行 sudo port install py27-pandas 来安装 Python 和所有依赖项。
安装 MacPorts 的缺点是,使用 python.org 版本的 Python 安装的任何软件包都不可用。最简单的方法是使用 MacPorts 重新安装它们,或者如果它们不是作为端口可用,则使用 MacPorts 版本的 pip
祝你好运!

好的。这是我的环境PATH的样子:PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/MacGPG2/bin。所以/opt/local/bin/usr/bin之前,缺少/Library/Frameworks/Python.framework/Versions/2.7/bin。虽然运行了sudo port install py27-pandas后一切似乎都安装成功了,但在我尝试导入pandas时,我得到了一个错误:ImportError: cannot import name urandom。虽然我检查了是否使用了正确的Python,使用了>>> import sys >>> from pprint import pprint as pp >>> pp(sys.path),但还是有问题。你有什么想法吗? - los_floppos
你能在问题的文本中发布ImportError的完整traceback吗?这将有助于确定问题出在哪里。 - MattDMo

0

非常奇怪。

看起来OSX自带的默认python 2.7安装pandas会有问题。

我只是安装了Python 3.3,然后它就正常工作了。

pythonbrew switch Python-3.3.1

pip install pandas


0
更新:我终于设法安装成功了(当然是在别人的帮助下...!)。 我不确定我是否正确和全面地记住了我所做的一切,但以下是一些要点:
我认为关键是你所拥有的numpy版本应该是1.6或更高,这样pandas才能正常安装。 然而,由Apple提供的默认Python安装只允许使用numpy 1.5.1版本。 顺便说一句,可能还有其他原因导致pandas不喜欢Mac OS X提供的Python,但关键仍然是你需要另一个Python版本。
因此,我从Python.org下载并安装了Python 2.7.6版本。
然后你可以运行“pip install --upgrade numpy”,它将升级到numpy 1.8。
注意: 如果“$ which python”给出的是新的Python.org Python 2.7.6版本,则您可能想要将“$ python pip install ...”作为第一行,因为pip的默认值为“/usr/bin/python”,因此会安装任何您正在为“旧”的默认Python版本安装的内容。
请注意,如果您使用scipy,则还应升级/重新安装scipy,以使numpy和scipy版本相对应。

希望这对任何人都有用...!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接