我正在尝试针对32位和64位体系结构编译SciPy,因为遵循few SO questions的建议,某些使用该库的应用程序只是一个体系结构或另一个体系结构.此命令对我有用大约两个月前的类似构建,但现在看来某些已编译的共享库仅针对x86_64:
sudo ARCHFLAGS =“-arch i386 -arch x86_64” pip install scipy
我已经尝试过该命令的多个版本,包括在sudo之前设置环境变量,包括在FFlags中使用-m32 -m64,使用OSX命令行工具,完整的Xcode安装,使用clang代替OSX附带的LLVM. official SciPy install instructions,而不是pip的easy_install甚至是./configure’ing等等,但是我似乎无法正常工作.奇怪的是,有些.so都是用两种体系结构构建的,但有些却没有:
dhcp-10-249-71-202:~ kastman$file /Library/Python/2.7/site-packages/scipy/optimize/*.so
/Library/Python/2.7/site-packages/scipy/optimize/_cobyla.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_lbfgsb.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_minpack.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_nnls.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_slsqp.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_zeros.so: Mach-O universal binary with 2 architectures
/Library/Python/2.7/site-packages/scipy/optimize/_zeros.so (for architecture i386): Mach-O bundle i386
/Library/Python/2.7/site-packages/scipy/optimize/_zeros.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/minpack2.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/moduleTNC.so: Mach-O universal binary with 2 architectures
/Library/Python/2.7/site-packages/scipy/optimize/moduleTNC.so (for architecture i386): Mach-O bundle i386
/Library/Python/2.7/site-packages/scipy/optimize/moduleTNC.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
查看make日志,看来似乎可以正常工作的库和不成功的库都成功传递了args:
# Minpack doesn't build fat binaries
/usr/local/bin/gfortran -Wall -Wall -undefined dynamic_lookup -bundle build/temp.macosx-10.7-intel-2.7/build/src.macosx-10.7-intel-2.7/scipy/optimize/minpack2/minpack2module.o build/temp.macosx-10.7-intel-2.7/build/src.macosx-10.7-intel-2.7/fortranobject.o build/temp.macosx-10.7-intel-2.7/scipy/optimize/minpack2/dcsrch.o build/temp.macosx-10.7-intel-2.7/scipy/optimize/minpack2/dcstep.o -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin11/4.6.2 -Lbuild/temp.macosx-10.7-intel-2.7 -lgfortran -o build/lib.macosx-10.7-intel-2.7/scipy/optimize/minpack2.so
building 'scipy.optimize._slsqp' extension
compiling C sources
C compiler: clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe
#... but moduleTNC does.
llvm-gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -Wl,-F. -arch i386 -arch x86_64 build/temp.macosx-10.7-intel-2.7/scipy/optimize/tnc/moduleTNC.o build/temp.macosx-10.7-intel-2.7/scipy/optimize/tnc/tnc.o -Lbuild/temp.macosx-10.7-intel-2.7 -o build/lib.macosx-10.7-intel-2.7/scipy/optimize/moduleTNC.so
building 'scipy.optimize._cobyla' extension
compiling C sources
C compiler: clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe
是否可能与我使用的gfortran编译器有所不同?我使用了brew install gfortran,根据SciPy文档,这应该很好.我认为重要的一行将是C编译器:clang行,这似乎几乎相同,包括-arch.
我尝试过的最后一个最详细的构建是:
sudo env ARCHFLAGS =“ -arch i386 -arch x86_64” ARCH =“ i386 x86_64” CC =“ clang” CXX =“ clang” FFLAGS =“-ff2c -m32 -m64” pip install scipy
有人对进一步诊断有任何建议吗?
(OSX 10.7,最新的MacBookPro,使用来自CLI工具和Xcode的gcc进行编译)
解决方法:
从源中提取和构建似乎可以正确创建胖二进制文件.我不确定这是否是已修复的错误(我在scipy开发人员列表上没有看到任何东西)还是与pip / easy_install有关,但这是我为使其正常工作所做的事情:
git clone https://github.com/scipy/scipy.git; cd scipy
export ARCHFLAGS='-arch i386 -arch x86_64'
python setup.py config
python setup.py build
sudo python setup.py install
没有特殊的CC环境变量,gfortran来自brew install gfortran,令人惊讶的是,看起来gcc是llvm-gcc.