使用Python 3.3在OSX上使用MKL构建NumPy时出错

时间:2013-04-01 12:38:07

标签: python c build numpy intel-mkl

背景

使用2012 iMac和第二代Core i7处理器,我正在尝试在OSX 10.8.3上构建NumPy 1.7.0(最终SciPY)链接到{{3包含在针对OSX的英特尔MKLC++ Composer XE 2013的评估版本中。我关注英特尔网站上的Fortran Composer XE 2013(在某些情况下,它在某些情况下并不是非常具体),用于设置,编译器标志等。

问题

使用:

$ python3 setup.py config build --compiler=intelem --fcompiler=intelem

$ python3 setup.py config --compiler=intelem --fcompiler=intelem build_clib --compiler=intelem --fcompiler=intelem build_ext --compiler=intelem --fcompiler=intelem

我得到同样的错误:

running build_clib
customize IntelEM64TCCompiler
customize IntelEM64TCCompiler using build_clib
running build_ext
customize IntelEM64TCCompiler
customize IntelEM64TCCompiler using build_ext
building 'numpy.core._dummy' extension
compiling C sources
C compiler: icc -m64 -march=corei7 -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -DMKL_ILP64 -I/opt/intel/mkl/include

compile options: '-Inumpy/core/include -Ibuild/src.macosx-10.8-x86_64-3.3/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/opt/local/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m -Ibuild/src.macosx-10.8-x86_64-3.3/numpy/core/src/multiarray -Ibuild/src.macosx-10.8-x86_64-3.3/numpy/core/src/umath -c'
icc: numpy/core/src/dummymodule.c
icc: command line warning #10121: overriding '-marchcorei7' with '-xhost'
icc -m64 -march=corei7 -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -DMKL_ILP64 -I/opt/intel/mkl/include -shared build/temp.macosx-10.8-x86_64-3.3/numpy/core/src/dummymodule.o -Lbuild/temp.macosx-10.8-x86_64-3.3 -o build/lib.macosx-10.8-x86_64-3.3/numpy/core/_dummy.so
icc: command line warning #10121: overriding '-marchcorei7' with '-xhost'
icc: command line warning #10006: ignoring unknown option '-shared'
Undefined symbols for architecture x86_64:
  "_PyModule_Create2", referenced from:
      _PyInit__dummy in dummymodule.o
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
icc: command line warning #10121: overriding '-marchcorei7' with '-xhost'
icc: command line warning #10006: ignoring unknown option '-shared'
Undefined symbols for architecture x86_64:
  "_PyModule_Create2", referenced from:
      _PyInit__dummy in dummymodule.o
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
error: Command "icc -m64 -march=corei7 -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -DMKL_ILP64 -I/opt/intel/mkl/include -shared build/temp.macosx-10.8-x86_64-3.3/numpy/core/src/dummymodule.o -Lbuild/temp.macosx-10.8-x86_64-3.3 -o build/lib.macosx-10.8-x86_64-3.3/numpy/core/_dummy.so" failed with exit status 1

我的LD_LIBRARY_PATHDYLD_LIBRARY_PATH都是:

/opt/intel/lib/intel64:/opt/intel/lib:/opt/intel/mkl/lib:/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib:/opt/local/lib:/usr/local/lib:/usr/lib

我的DYLD_FRAMEWORK_PATH是:

/opt/local/Library/Frameworks:/Library/Frameworks:/System/Library/Frameworks

我的site.cfg是:

[DEFAULT]
library_dirs = /opt/intel/lib/intel64:/opt/intel/lib:/opt/intel/mkl/lib:/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib:/opt/local/lib:/usr/local/lib:/usr/lib
include_dirs = /opt/intel/include:/opt/intel/include/intel64:/opt/intel/mkl/include:/opt/local/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m:/opt/local/include:/usr/local/include:/usr/include

[mkl]
library_dirs = /opt/intel/lib/intel64:/opt/intel/lib:/opt/intel/mkl/lib:/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib:/opt/local/lib:/usr/local/lib:/usr/lib
include_dirs = /opt/intel/include:/opt/intel/include/intel64:/opt/intel/mkl/include:/opt/local/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m:/opt/local/include:/usr/local/include:/usr/include
mkl_libs = mkl_rt
lapack_libs = mkl_lapack

iccifort的符号链接位于/usr/bin并且正常运行。 dummymodule.c的内容可在this article的numpy存储库中找到。我不是C程序员,所以我不能马上看到什么是错的。我使用MacPorts python 3.3.0(使用上面的设置)和python.org 3.3.0得到了这个错误,修改了设置指向它而不是/opt/local

恳求

任何人都可以帮忙解决这个问题吗?

修改

我为-shared换了-dynamiclib,现在正在接受:

building extension "numpy.random.mtrand" sources
C compiler: icc -m64 -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -DMKL_ILP64

compile options: '-Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/opt/local/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c'
icc: _configtest.c
icc -m64 -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -DMKL_ILP64 _configtest.o -o _configtest
_configtest
failure.
removing: _configtest.c _configtest.o _configtest
building data_files sources
build_src: building npy-pkg config files
running build_py
copying numpy/version.py -> build/lib.macosx-10.8-x86_64-3.3/numpy
copying build/src.macosx-10.8-x86_64-3.3/numpy/__config__.py -> build/lib.macosx-10.8-x86_64-3.3/numpy
copying numpy/distutils/intelccompiler.py -> build/lib.macosx-10.8-x86_64-3.3/numpy/distutils
copying build/src.macosx-10.8-x86_64-3.3/numpy/distutils/__config__.py -> build/lib.macosx-10.8-x86_64-3.3/numpy/distutils
copying numpy/distutils/fcompiler/intel.py -> build/lib.macosx-10.8-x86_64-3.3/numpy/distutils/fcompiler
running build_clib
customize IntelEM64TCCompiler
customize IntelEM64TCCompiler using build_clib
running build_ext
customize IntelEM64TCCompiler
customize IntelEM64TCCompiler using build_ext
building 'numpy.core._dummy' extension
compiling C sources
C compiler: icc -m64 -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -DMKL_ILP64

compile options: '-Inumpy/core/include -Ibuild/src.macosx-10.8-x86_64-3.3/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/opt/local/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c'
icc: numpy/core/src/dummymodule.c
icc -m64 -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -DMKL_ILP64 -dynamiclib build/temp.macosx-10.8-x86_64-3.3/numpy/core/src/dummymodule.o -Lbuild/temp.macosx-10.8-x86_64-3.3 -o build/lib.macosx-10.8-x86_64-3.3/numpy/core/_dummy.so
Undefined symbols for architecture x86_64:
  "_PyModule_Create2", referenced from:
      _PyInit__dummy in dummymodule.o
ld: symbol(s) not found for architecture x86_64
Undefined symbols for architecture x86_64:
  "_PyModule_Create2", referenced from:
      _PyInit__dummy in dummymodule.o
ld: symbol(s) not found for architecture x86_64
error: Command "icc -m64 -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -DMKL_ILP64 -dynamiclib build/temp.macosx-10.8-x86_64-3.3/numpy/core/src/dummymodule.o -Lbuild/temp.macosx-10.8-x86_64-3.3 -o build/lib.macosx-10.8-x86_64-3.3/numpy/core/_dummy.so" failed with exit status 1

所以,我在_configtest之后得到一行failure.(不确定那是什么)以及下面的相同错误。想法?

2 个答案:

答案 0 :(得分:3)

  

icc:命令行警告#10006:忽略未知选项'-shared'

这是一个问题。您的编译器正在尝试构建可执行文件,即使它已被告知要构建共享库。根据icc文档,-shared仅适用于Linux系统。由于你的是MacOSX系统,我认为你想要使用-dynamiclib

编辑:我怀疑您错过了pylib的链接,位于:icc -m64 -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -DMKL_ILP64 -dynamiclib build/temp.macosx-10.8-x86_64-3.3/numpy/core/src/dummymodule.o -Lbuild/temp.macosx-10.8-x86_64-3.3 -o build/lib.macosx-10.8-x86_64-3.3/numpy/core/_dummy.so

缺少的链接导致:

Undefined symbols for architecture x86_64:
  "_PyModule_Create2", referenced from:
      _PyInit__dummy in dummymodule.o
ld: symbol(s) not found for architecture x86_64

您需要添加-lpythonX.Y,其中X.Y表示您要链接的Python版本。如果此文件存在,但链接器找不到它,则需要使用-Llink/search/directory(例如-Llib/)指令告诉链接器它在哪里。如果文件不存在,则需要构建它。

答案 1 :(得分:1)

我建议您将文件numpy-1.7.0 / numpy / distutils / intelccompiler.py第37行更改为

icc -m64 -fPIC -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost -undefined dynamic_lookup -bundle -DMKL_ILP64

这项工作对我来说,我在

之前有这个编译错误