在OS X 10.7.4上安装NumPy for Python 3.2.3

我已经尝试了几个月来为Python 3安装numpy但是尽管有大量的谷歌搜索,甚至发布到numpy邮件列表,我仍然没有接近解决方案.

我已经设法通过MacPorts安装它但不幸的是,似乎没有Python 3的MatPlotLib端口,这是我试图安装numpy的主要原因…所以我有点卡住…

尝试从setup.py文件构建时,我一直收到同样的错误.我在下面列出了终端输出.

谢谢你尽你所能的帮助,

亚当.

这是终端输出:

lipo: can't figure out the architecture type of: /var/folders/zj/7xymy_2n3s71ws30v3v_qnlw0000gn/T//ccbRr0Hj.out
failure.
removing: _configtest.c _configtest.o
Running from numpy source directory.Traceback (most recent call last):
  File "setup.py", line 214, in <module>
    setup_package()
  File "setup.py", line 207, in setup_package
    configuration=configuration )
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/core.py", line 186, in setup
    return old_setup(**new_attr)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 917, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build.py", line 37, in run
    old_build.run(self)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/command/build.py", line 126, in run
    self.run_command(cmd_name)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 152, in run
    self.build_sources()
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 169, in build_sources
    self.build_extension_sources(ext)
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 328, in build_extension_sources
    sources = self.generate_sources(sources, ext)
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 385, in generate_sources
    source = func(extension, build_dir)
  File "numpy/core/setup.py", line 410, in generate_config_h
    moredefs, ignored = cocache.check_types(config_cmd, ext, build_dir)
  File "numpy/core/setup.py", line 41, in check_types
    out = check_types(*a, **kw)
  File "numpy/core/setup.py", line 271, in check_types
    "Cannot compile 'Python.h'. Perhaps you need to "\
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
最佳答案
好吧,我终于设法让NumPy安装了.不确定它是最好的方法,但它似乎工作!

首先我需要安装分发:

> curl http://python-distribute.org/distribute_setup.py | python3

然后我安装了pip:

> curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3

之后我不得不进入我的系统路径(再次可能有更好的方法):

>开放式终端
>键入以下内容(单行):

> sudo ln -s /Library/Frameworks/Python.framework/Versions/3.2/bin/pip /usr/local / bin

安装了distribute和pip后,我安装了Nose,NumPy需要进行测试或者其他东西:

>再次,在终端类型中,以下内容:

> pip安装鼻子

现在我需要确保我有最新版本的Xcode:

>从AppStore安装最新版本的Xcode
>如果你还有一个/ Developer文件夹,那么将它重命名为Developer-old(不确定这是否会在以后给我带来问题)
>打开终端并创建一个符号链接到AppStore版本的Xcode(单行):

> sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer / Developer

所有这些都是安装NumPy的时间:

>从以下网址下载NumPy源代码:http://sourceforge.net/projects/numpy/files/NumPy/1.6.2rc1/
>取消归档文件
>再次打开终端:

> cd到通过取消归档文件创建的目录,例如

> cd /Users/username/Downloads/numpy-1.6.2rc1

>在下面键入终端以更改用于构建NumPy的编译器:

>导出CC = clang
>导出CXX = clang
>导出FFLAGS = -ff2c
> export LDSHARED =’clang -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -g'(这是一行)
> python3 setup.py build(这可能需要一段时间)
> python3 setup.py安装

好的,假设没有错误,应该安装NumPy.是时候测试一下了:

>打开IDLE
>在Python Shell类型中:

>导入numpy
> numpy.test(‘完整’)

>这将测试NumPy我用Python 3.2.3收到的最终结果是:

>< nose.result.TextTestResult run = 3192 errors = 0 failures = 1>

因此NumPy安装除了一个测试外都通过了所有测试,看起来非常好.我还没有机会看到是否正常工作,因为我仍在努力安装matplotlib ……

希望这些说明对某人有用!

亚当.

转载注明原文:在OS X 10.7.4上安装NumPy for Python 3.2.3 - 代码日志