Skip to main content
 首页 » 编程设计

python之'f2py -c --help-fcompiler' 挂起

2024年12月31日7Terrylee

当我运行命令时

f2py --c -help-fcompiler 

f2py 打印以下输出,然后无限期挂起

Gnu95FCompiler instance properties: 
  archiver        = ['/usr/bin/gfortran', '-cr'] 
  compile_switch  = '-c' 
  compiler_f77    = ['/usr/bin/gfortran', '-Wall', '-g', '-ffixed-form', '- 
                    fno-second-underscore', '-fPIC', '-O3', '-funroll-loops'] 
  compiler_f90    = ['/usr/bin/gfortran', '-Wall', '-g', '-fno-second- 
                    underscore', '-fPIC', '-O3', '-funroll-loops'] 
  compiler_fix    = ['/usr/bin/gfortran', '-Wall', '-g', '-ffixed-form', '- 
                    fno-second-underscore', '-Wall', '-g', '-fno-second- 
                    underscore', '-fPIC', '-O3', '-funroll-loops'] 
  libraries       = ['gfortran'] 
  library_dirs    = ['/usr/lib/gcc/x86_64-linux-gnu/7', '/usr/lib/gcc/x86_64 
                    -linux-gnu/7'] 
  linker_exe      = ['/usr/bin/gfortran', '-Wall', '-Wall'] 
  linker_so       = ['/usr/bin/gfortran', '-Wall', '-g', '-Wall', '-g', '- 
                    shared'] 
  object_switch   = '-o ' 
  ranlib          = ['/usr/bin/gfortran'] 
  version         = LooseVersion ('7') 
  version_cmd     = ['/usr/bin/gfortran', '-dumpversion'] 

当我使用 ctrl+c 手动终止进程时,它看起来像是卡在了这里:

TEST_ENV/lib/python3.6/site-packages/numpy/distutils/fcompiler/__init__.py", line 472, in customize 
    posix=(os.name == 'posix')) 
  File "/usr/lib/python3.6/shlex.py", line 305, in split 
    return list(lex) 
  File "/usr/lib/python3.6/shlex.py", line 295, in __next__ 
    token = self.get_token() 
  File "/usr/lib/python3.6/shlex.py", line 105, in get_token 
    raw = self.read_token() 
  File "/usr/lib/python3.6/shlex.py" 

这一切都在使用 numpy 1.16.0 的干净虚拟环境中

有人知道为什么会这样吗?

请您参考如下方法:

这是 numpy 中的一个已知错误(已修复并向后移植到 1.16.1):

参见https://github.com/numpy/numpy/pull/12843

原因

f2py -c --help-compiler 

在 Ubuntu 18.04 上无限期挂起是因为在 None 上调用了 shlex.split()。

当 show_fcompilers() 调用 customize() 和 self.command_vars 时,这发生在 fcompiler/__init__.py 的第 471 行.compiler_f77 = f77, self.command_vars.compiler_f90 = None