尝试使用f2py换行时出错(最小工作示例)

时间:2016-12-21 06:39:43

标签: python fortran cygwin f2py

我试图运行列出的Minimum working example文件:
https://docs.scipy.org/doc/numpy-dev/f2py/getting-started.html

在Cygwin中运行以下命令

python c:/Python27/Scripts/f2py.py -c fib1.f -m fib1 --compiler=mingw32

该命令退出时出现以下错误:

error: Command "gcc -O2 -Wall -Wstrict-prototypes -DNPY_MINGW_USE_CUSTOM_MSVCR -D__MSVCRT_VERSION__=0x0900 -Ic:\cygwin\tmp\tmprggtye\src.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c c:\cygwin\tmp\tmprggtye\src.win32-2.7\fib1module.c -o c:\cygwin\tmp\tmprggtye\Release\cygwin\tmp\tmprggtye\src.win32-2.7\fib1module.o" failed with exit status 1

以下是控制台上打印的整个输出:

$ python c:/Python27/Scripts/f2py.py -c fib1.f -m fib1 --compiler=mingw32
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 extension "fib1" sources
f2py options: []
f2py:> c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c
creating c:\cygwin\tmp\tmpucrmay\src.win32-2.7
Reading fortran codes...
        Reading file 'fib1.f' (format:fix,strict)
Post-processing...
        Block: fib1
                        Block: fib
Post-processing (stage 2)...
Building modules...
        Building module "fib1"...
                Constructing wrapper function "fib"...
                  fib(a,[n])
        Wrote C/API module "fib1" to file "c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c"
  adding 'c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fortranobject.c' to sources.
  adding 'c:\cygwin\tmp\tmpucrmay\src.win32-2.7' to include_dirs.
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\cygwin\tmp\tmpucrmay\src.win32-2.7
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\cygwin\tmp\tmpucrmay\src.win32-2.7
build_src: building npy-pkg config files
running build_ext
Cannot build msvcr library: "msvcr90d.dll" not found
customize Mingw32CCompiler
customize Mingw32CCompiler using build_ext
customize GnuFCompiler
Could not locate executable g77
Could not locate executable f77
customize IntelVisualFCompiler
Could not locate executable ifort
Could not locate executable ifl
customize AbsoftFCompiler
Could not locate executable f90
customize CompaqVisualFCompiler
Found executable C:\cygwin\bin\DF.exe
Found executable C:\cygwin\bin\DF.exe
customize IntelItaniumVisualFCompiler
Could not locate executable efl
customize Gnu95FCompiler
Found executable C:\cygwin\bin\gfortran.exe
Found executable C:\cygwin\bin\gfortran.exe
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
building 'fib1' extension
compiling C sources
C compiler: gcc -O2 -Wall -Wstrict-prototypes

creating c:\cygwin\tmp\tmpucrmay\Release
creating c:\cygwin\tmp\tmpucrmay\Release\cygwin
creating c:\cygwin\tmp\tmpucrmay\Release\cygwin\tmp
creating c:\cygwin\tmp\tmpucrmay\Release\cygwin\tmp\tmpucrmay
creating c:\cygwin\tmp\tmpucrmay\Release\cygwin\tmp\tmpucrmay\src.win32-2.7
compile options: '-DNPY_MINGW_USE_CUSTOM_MSVCR -D__MSVCRT_VERSION__=0x0900 -Ic:\cygwin\tmp\tmpucrmay\src.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c'
gcc -O2 -Wall -Wstrict-prototypes -DNPY_MINGW_USE_CUSTOM_MSVCR -D__MSVCRT_VERSION__=0x0900 -Ic:\cygwin\tmp\tmpucrmay\src.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c -o c:\cygwin\tmp\tmpucrmay\Release\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.o
Found executable C:\cygwin\bin\gcc.exe
In file included from C:\Python27\include/Python.h:86:0,
                 from c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:17:
C:\Python27\include/intobject.h:46:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyInt_AsUnsignedLongLongMask’
 PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
                                   ^
In file included from C:\Python27\include/Python.h:88:0,
                 from c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:17:
C:\Python27\include/longobject.h:50:1: warning: parameter names (without types) in function declaration
 PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG);
 ^
In file included from C:\Python27\include/Python.h:58:0,
                 from c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:17:
C:\Python27\include/pyconfig.h:314:23: error: unknown type name ‘__int64’
 # define PY_LONG_LONG __int64
                       ^
C:\Python27\include/pyport.h:793:34: note: in definition of macro ‘PyAPI_FUNC’
 #       define PyAPI_FUNC(RTYPE) RTYPE
                                  ^
C:\Python27\include/longobject.h:52:12: note: in expansion of macro ‘PY_LONG_LONG’
 PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);
            ^
In file included from C:\Python27\include/Python.h:88:0,
                 from c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:17:
C:\Python27\include/longobject.h:53:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyLong_AsUnsignedLongLong’
 PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
                                   ^
C:\Python27\include/longobject.h:54:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyLong_AsUnsignedLongLongMask’
 PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);
                                   ^
In file included from C:\Python27\include/Python.h:58:0,
                 from c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:17:
C:\Python27\include/pyconfig.h:314:23: error: unknown type name ‘__int64’
 # define PY_LONG_LONG __int64
                       ^
C:\Python27\include/pyport.h:793:34: note: in definition of macro ‘PyAPI_FUNC’
 #       define PyAPI_FUNC(RTYPE) RTYPE
                                  ^
C:\Python27\include/longobject.h:55:12: note: in expansion of macro ‘PY_LONG_LONG’
 PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);
            ^
In file included from C:\Python27\include/Python.h:8:0,
                 from c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:17:
C:\Python27\include/pyconfig.h:314:23: error: unknown type name ‘__int64’
 # define PY_LONG_LONG __int64
                       ^
C:\Python27\lib\site-packages\numpy\core\include/numpy/npy_common.h:263:9: note: in expansion of macro ‘PY_LONG_LONG’
 typedef PY_LONG_LONG npy_longlong;
         ^
In file included from C:\Python27\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:4:0,
                 from C:\Python27\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:18,
                 from C:\Python27\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                 from /tmp/tmpucrmay/src.win32-2.7/fortranobject.h:13,
                 from c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:19:
C:\Python27\lib\site-packages\numpy\core\include/numpy/npy_common.h:264:31: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘npy_ulonglong’
 typedef unsigned PY_LONG_LONG npy_ulonglong;
                               ^
In file included from C:\Python27\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:4:0,
                 from C:\Python27\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:18,
                 from C:\Python27\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                 from /tmp/tmpucrmay/src.win32-2.7/fortranobject.h:13,
                 from c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:19:
C:\Python27\lib\site-packages\numpy\core\include/numpy/npy_common.h:566:17: error: unknown type name ‘npy_ulonglong’
         typedef npy_ulonglong npy_uint64;
                 ^
In file included from C:\Python27\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:1781:0,
                 from C:\Python27\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:18,
                 from C:\Python27\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                 from /tmp/tmpucrmay/src.win32-2.7/fortranobject.h:13,
                 from c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:19:
C:\Python27\lib\site-packages\numpy\core\include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c: In function ‘initfib1’:
c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:331:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   Py_TYPE(&PyFortran_Type) = &PyType_Type;
   ^
c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c: At top level:
c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c:112:12: warning: ‘f2py_size’ defined but not used [-Wunused-function]
 static int f2py_size(PyArrayObject* var, ...)
            ^
error: Command "gcc -O2 -Wall -Wstrict-prototypes -DNPY_MINGW_USE_CUSTOM_MSVCR -D__MSVCRT_VERSION__=0x0900 -Ic:\cygwin\tmp\tmpucrmay\src.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c c:\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.c -o c:\cygwin\tmp\tmpucrmay\Release\cygwin\tmp\tmpucrmay\src.win32-2.7\fib1module.o" failed with exit status 1

我已经倾注了大量的链接,试图找到一些无济于事的解决方案 如果有人可以帮我解决这个问题,将不胜感激 我使用的是Windows 7(64位)和Python 2.7.11。

1 个答案:

答案 0 :(得分:0)

发布我为后人所做的事情
在尝试了评论中提到的内容之后(不记得所有内容),我尝试了以下内容:

python c:/Python27/Scripts/f2py.py -c fib1.f -m fib1 --compiler=msvc --fcompiler==g77

g77是一个现成的fortran编译器(任何其他fortran编译器应该工作)。

我最终遇到了以下错误:

$ python c:/Python27/Scripts/f2py.py -c fib1.f -m fib1 --compiler=msvc  --fcompiler=g77
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
  commands have different --compiler options: ['mingw32', 'msvc'], using first in list as default
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "fib1" sources
f2py options: []
f2py:> c:\cygwin\tmp\tmpn3krmz\src.win32-2.7\fib1module.c
creating c:\cygwin\tmp\tmpn3krmz\src.win32-2.7
Reading fortran codes...
        Reading file 'fib1.f' (format:fix,strict)
Post-processing...
        Block: fib1
                        Block: fib
Post-processing (stage 2)...
Building modules...
        Building module "fib1"...
                Constructing wrapper function "fib"...
                  fib(a,[n])
        Wrote C/API module "fib1" to file "c:\cygwin\tmp\tmpn3krmz\src.win32-2.7\fib1module.c"
  adding 'c:\cygwin\tmp\tmpn3krmz\src.win32-2.7\fortranobject.c' to sources.
  adding 'c:\cygwin\tmp\tmpn3krmz\src.win32-2.7' to include_dirs.
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\cygwin\tmp\tmpn3krmz\src.win32-2.7
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\cygwin\tmp\tmpn3krmz\src.win32-2.7
build_src: building npy-pkg config files
running build_ext
customize MSVCCompiler
customize MSVCCompiler using build_ext
customize GnuFCompiler
Could not locate executable g77
Could not locate executable f77
customize IntelVisualFCompiler
Could not locate executable ifort
Could not locate executable ifl
customize AbsoftFCompiler
Could not locate executable f90
customize CompaqVisualFCompiler
Found executable C:\cygwin\bin\DF.exe
Found executable C:\cygwin\bin\DF.exe
customize IntelItaniumVisualFCompiler
Could not locate executable efl
customize Gnu95FCompiler
Found executable C:\cygwin\bin\gfortran.exe
Found executable C:\cygwin\bin\gfortran.exe
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
building 'fib1' extension
compiling C sources
error: Unable to find vcvarsall.bat

为了摆脱最后的错误,我从中获取灵感 1)error: Unable to find vcvarsall.bat
2)How do I point easy_install to vcvarsall.bat?

我将vcvarsall.bat C:/Python27/Lib/distutils/msvc9compilerfind_vcvarsall()的位置硬编码到变量toolsdirproductdir的第245和249行。

我这样做了,因为设置2(上面)中提到的环境变量不起作用。

可能不是一个优雅的解决方案,但它确实有用。