Skip to main content
 首页 » 编程设计

python之Numpy 安装/构建 Mac Osx

2025年05月04日20oomusou

所以我按照本网站上的说明进行操作 http://www.scipy.org/Installing_SciPy/Mac_OS_X ,下载 Xcode 和 Fortran Gcc,然后从终端运行以下命令:

Megans-MacBook-Pro:~ MeganRCunninghan$ export CC=clang 
Megans-MacBook-Pro:~ MeganRCunninghan$ export CXX=clang 
Megans-MacBook-Pro:~ MeganRCunninghan$ export FFLAGS=-ff2c 
Megans-MacBook-Pro:~ MeganRCunninghan$ git clone https://github.com/numpy/numpy.git 
fatal: destination path 'numpy' already exists and is not an empty directory. 
Megans-MacBook-Pro:~ MeganRCunninghan$ python setup.py build 
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory 
Megans-MacBook-Pro:~ MeganRCunninghan$ ls 
Desktop     Dropbox     Pictures    my_new_env  virtualenv.pyc 
Django      Library     Public      numpy 
Documents   Movies      Sync Folder pip 
Downloads   Music       git     virtualenv.py 
Megans-MacBook-Pro:~ MeganRCunninghan$ cd numpy 
Megans-MacBook-Pro:numpy MeganRCunninghan$ python setup.py build 
Running from numpy source directory. 
non-existing path in 'numpy/distutils': 'site.cfg' 
F2PY Version 2 
numpy/core/setup_common.py:86: MismatchCAPIWarning: API mismatch detected, the C API version numbers have to be updated. Current C api version is 8, with checksum f4362353e2d72f889fda0128aa015037, but recorded checksum for C API version 8 in codegen_dir/cversions.txt is 17321775fc884de0b1eda478cd61c74b. If functions were added in the C API, you have to update C_API_VERSION  in numpy/core/setup_common.py. 
  MismatchCAPIWarning) 
blas_opt_info: 
  FOUND: 
    extra_link_args = ['-Wl,-framework', '-Wl,Accelerate'] 
    define_macros = [('NO_ATLAS_INFO', 3)] 
    extra_compile_args = ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers'] 
 
lapack_opt_info: 
  FOUND: 
    extra_link_args = ['-Wl,-framework', '-Wl,Accelerate'] 
    define_macros = [('NO_ATLAS_INFO', 3)] 
    extra_compile_args = ['-msse3'] 
 
running build 
running config_cc 
unifing config_cc, config, build_clib, build_ext, build commands --compiler options 
running config_fc 
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options 
running build_src 
build_src 
building py_modules sources 
creating build 
creating build/src.macosx-10.6-intel-2.7 
creating build/src.macosx-10.6-intel-2.7/numpy 
creating build/src.macosx-10.6-intel-2.7/numpy/distutils 
building library "npymath" sources 
customize Gnu95FCompiler 
Could not locate executable gfortran 
Could not locate executable f95 
customize NAGFCompiler 
customize AbsoftFCompiler 
Could not locate executable f90 
Could not locate executable f77 
customize IBMFCompiler 
Could not locate executable xlf90 
Could not locate executable xlf 
customize IntelFCompiler 
Could not locate executable ifort 
Could not locate executable ifc 
customize GnuFCompiler 
Could not locate executable g77 
customize G95FCompiler 
Could not locate executable g95 
customize PGroupFCompiler 
Could not locate executable pgfortran 
don't know how to compile Fortran code on platform 'posix' 
C compiler: clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 
 
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/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c' 
clang: _configtest.c 
sh: clang: command not found 
sh: clang: command not found 
failure. 
removing: _configtest.c _configtest.o 
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/MeganRCunninghan/numpy/numpy/distutils/core.py", line 184, in setup 
    return old_setup(**new_attr) 
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup 
    dist.run_commands() 
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands 
    self.run_command(cmd) 
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command 
    cmd_obj.run() 
  File "/Users/MeganRCunninghan/numpy/numpy/distutils/command/build.py", line 37, in run 
    old_build.run(self) 
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build.py", line 127, in run 
    self.run_command(cmd_name) 
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command 
    self.distribution.run_command(command) 
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command 
    cmd_obj.run() 
  File "/Users/MeganRCunninghan/numpy/numpy/distutils/command/build_src.py", line 152, in run 
    self.build_sources() 
  File "/Users/MeganRCunninghan/numpy/numpy/distutils/command/build_src.py", line 163, in build_sources 
    self.build_library_sources(*libname_info) 
  File "/Users/MeganRCunninghan/numpy/numpy/distutils/command/build_src.py", line 298, in build_library_sources 
    sources = self.generate_sources(sources, (lib_name, build_info)) 
  File "/Users/MeganRCunninghan/numpy/numpy/distutils/command/build_src.py", line 385, in generate_sources 
    source = func(extension, build_dir) 
  File "numpy/core/setup.py", line 644, in get_mathlib_info 
    raise RuntimeError("Broken toolchain: cannot link a simple C program") 
RuntimeError: Broken toolchain: cannot link a simple C program 

我已经为此工作了几个小时,现在迷路了。

请您参考如下方法:

下载 Xcode 4 后,您需要安装它的 Command Line Tools 组件。启动 Xcode,然后选择 Xcode -> Preferences -> Downloads -> Components .这将安装 clang 和其他构建工具,以便可以从命令行使用它们。