h5py在安装后出错

Gil*_*les 5 python compilation hdf5 h5py

可能重复:
在OS X上安装h5py

我想让h5py在我的OS X Lion 10.7.3 Macbook Pro上运行.它以前工作过,但不知怎的,它已经卸载,我无法再次安装它.它似乎与安装XCode 4.3有关,但我不确定.

导入h5py时,出现以下错误:

>>> import h5py


   Traceback (most recent call last):

  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/h5py/__init__.py", line 1, in <module>
    from h5py import _errors
ImportError: dlopen(/Library/Python/2.7/site-packages/h5py/_errors.so, 2): Symbol not found: _H5E_ALREADYEXISTS_g
  Referenced from: /Library/Python/2.7/site-packages/h5py/_errors.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/h5py/_errors.so
Run Code Online (Sandbox Code Playgroud)

我想这与HDF5库有关.它还没有安装,所以我先安装它

brew install hdf5
Run Code Online (Sandbox Code Playgroud)

这没有错误.但最后的警告如下.我认为这很重要:

ld: warning: ignoring file ../hdf5-1.8.8/hdf5/lib/libhdf5.a, 
file was built for archive which is not the architecture being linked (i386)
Run Code Online (Sandbox Code Playgroud)

我不是100%肯定这意味着什么,但我想这个库是针对i386架构编译的,但是这个目录中有更多文件它不会抱怨:

libhdf5.la
libhdf5.dylib -> libhdf5.7.dylib
libhdf5.7.dylib
libhdf5.settings
libhdf5.a
libhdf5_hl.la
libhdf5_hl.dylib -> libhdf5_hl.7.dylib
libhdf5_hl.a
libhdf5_hl.7.dylib
Run Code Online (Sandbox Code Playgroud)

后来我也自己编译了源代码,从HDF5组网站(http://www.hdfgroup.org/HDF5/)下载.使用以下配置行,以确保它创建共享库我添加了--enable-shared和disabled fortran:

./configure --with-zlib=/usr/local --disable-fortran 
--prefix=/usr/local/ --target=x86_64-apple-darwin 
-build=x86_64-apple-darwin --host=x86_64-apple-darwin 
--enable-shared --disable-production
Run Code Online (Sandbox Code Playgroud)

我已经删除了h5py和hdf5库并重新安装了几次(我自己编译h5py,如使用pip和easy_install),但这似乎没有帮助.

我还使用我刚刚使用此命令创建的构建安装了h5py:

python setup.py build --hdf5=../hdf5-1.8.8/hdf5
Run Code Online (Sandbox Code Playgroud)

我还将我的numpy和scipy安装更新到最新版本.

noi*_*oio 6

从干净安装的Mac OS X Lion,我必须做的是以下内容:

  • 使用命令行工具安装Xcode
  • 安装Homebrew
  • 告诉Homebrew Xcode在哪里(xcode-select ...)

然后我可以:

$ brew install hdf5
Run Code Online (Sandbox Code Playgroud)

它没有正确链接,因为我/usr/local/lib不可写.检查brew doctor是否有任何未链接的包:

$ brew doctor
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built.

    hdf5
    szip
Run Code Online (Sandbox Code Playgroud)

所以我让dir可写并使用了

$ brew link hdf5
$ brew link szip
Run Code Online (Sandbox Code Playgroud)

然后我就能做到

$ sudo pip install h5py
Run Code Online (Sandbox Code Playgroud)

并且presto.

>>> import h5py
>>> 
Run Code Online (Sandbox Code Playgroud)