Ошибка при попытке обтекания с использованием 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 ответ
Размещать то, что я сделал для потомков
Сразу после того, как опробовал вещи, упомянутые в комментариях и еще кое-что (не помню их всех), я попытался сделать следующее:
python c:/Python27/Scripts/f2py.py -c fib1.f -m fib1 --compiler=msvc --fcompiler==g77
g77 - готовый компилятор фортрана (любой другой компилятор фортрана должен работать).
Я закончил со следующими ошибками:
$ 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) ошибка: невозможно найти vcvarsall.bat
2) Как мне указать easy_install на vcvarsall.bat?
Я жестко закодировал местоположение vcvarsall.bat
в C:/Python27/Lib/distutils/msvc9compiler
в find_vcvarsall()
функция в переменные toolsdir
а также productdir
в строках 245 и 249.
Я сделал это, так как установка переменной среды, как указано в 2 (выше), не работала.
Не может быть элегантным решением, но это сработало.