在OS X 10.7.4上安装NumPy for Python 3.2.3 [英] Install NumPy for Python 3.2.3 on OS X 10.7.4
问题描述
我几个月来一直在尝试为Python 3安装numpy,但是尽管有大量的Google搜索,甚至将其发布到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
之后,我必须 pip 进入我的系统路径(同样可能有更好的方法):
- 打开终端
- 键入以下内容(单行):
-
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.2/bin/pip /usr/local/bin
-
在安装了 distribution 和 pip 之后,我安装了 Nose ,NumPy需要进行测试或进行以下操作:
- 再次在终端中输入以下内容:
-
pip install nose
-
现在,我需要确保拥有最新版本的 Xcode :
- 从 AppStore 安装最新版本的 Xcode
- 如果您仍然有
/Developer
文件夹,则将其重命名为Developer-old
(不确定以后是否会给我带来麻烦) - 打开终端,并创建指向Xcode的AppStore版本的符号链接(单行):
-
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
-
-
- 在 Terminal 中键入以下内容,以更改用于构建 NumPy 的编译器:
-
export CC=clang
-
export CXX=clang
-
export 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 install
-
好的,假设没有错误,请安装 NumPy .是时候测试一下了:
- 打开 IDLE
- 在 Python Shell 中输入:
-
import numpy
-
numpy.test('full')
-
- 这将测试 NumPy ,我通过 Python 3.2.3 收到的最终结果是:
-
<nose.result.TextTestResult run=3192 errors=0 failures=1>
-
因此 NumPy 安装通过了除一项测试以外的所有测试,这看起来还不错.由于我仍在努力安装 matplotlib ,我还没有机会查看是否能正常工作...
希望这些说明对某人有用!
亚当.
I have been trying for months to get numpy installed for Python 3 but despite copious amounts of Googling and even posting to the numpy mailing list I am still no closer to a solution.
I have managed to get it installed via MacPorts but unfortunately there doesn't appear to be a port of MatPlotLib for Python 3 which is the main reason I am trying to install numpy...so I am a bit stuck...
I keep getting the same error whilst trying to build from the setup.py file. I have included the terminal output below.
Thanks for any help you can offer,
Adam.
Here is the terminal output:
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.
Well, I finally managed to get NumPy to install. Not sure it is the best method but it seems to work!
First of all i needed to install distribute:
curl http://python-distribute.org/distribute_setup.py | python3
Then I installed pip:
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3
After that I had to get pip on to my system path (again there are probably better ways):
- Open Terminal
- Type the following (single line):
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.2/bin/pip /usr/local/bin
With distribute and pip installed I then installed Nose, which NumPy needs for testing or something:
- Again, in Terminal type the following:
pip install nose
Now I needed to make sure I had the latest version of Xcode:
- From the AppStore install the latest version of Xcode
- If you still have a
/Developer
folder then rename itDeveloper-old
(not sure whether this will cause problems for me later or not) - Open Terminal and create a symlink to the AppStore version of Xcode (single line):
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer /Developer
With all of that out of the way time to install NumPy:
- Download the NumPy source from: http://sourceforge.net/projects/numpy/files/NumPy/1.6.2rc1/
- Unarchive the file
- Open Terminal again:
cd
into the directory created by unarchiving the file e.g.cd /Users/username/Downloads/numpy-1.6.2rc1
- Type into the Terminal the following to change the complier used to build NumPy:
export CC=clang
export CXX=clang
export FFLAGS=-ff2c
export LDSHARED='clang -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -g'
(this is a single line)python3 setup.py build
(this may take a while)python3 setup.py install
Okay, assuming there were no errors NumPy should be installed. Time to test it out:
- Open IDLE
- In the Python Shell type:
import numpy
numpy.test('full')
- This will test NumPy the final result I received with Python 3.2.3 was:
<nose.result.TextTestResult run=3192 errors=0 failures=1>
So the NumPy installation passes all except one test, which seems pretty good. I haven't had a chance to see if works properly yet as I am still struggling to get matplotlib installed...
Hope these instructions are useful to somebody!
Adam.
这篇关于在OS X 10.7.4上安装NumPy for Python 3.2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!