I was trying to run the Minimum working example
file listed at:
https://docs.scipy.org/doc/numpy-dev/f2py/getting-started.html
Upon running the following command in Cygwin
python c:/Python27/Scripts/f2py.py -c fib1.f -m fib1 --compiler=mingw32
The command exits with the following error:
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
Below is the entire output printed on the console:
$ 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
I have poured over a lot of links trying to find some solution to no avail.
Will be grateful if someone could help me with the problem.
I am using Windows 7 (64 bit) and Python 2.7.11.
Posting what I did for posterity sake
Right after trying out the things mentioned in the comments and some more (can't remember them all), I attempted the following:
g77 being an off the shelf fortran compiler (any other fortran compiler should work).
I ended up with the following errors:
To get rid of the final error, I took inspiration from
1) error: Unable to find vcvarsall.bat
2) How do I point easy_install to vcvarsall.bat?
I hardcoded the location of
vcvarsall.bat
intoC:/Python27/Lib/distutils/msvc9compiler
atfind_vcvarsall()
function into the variablestoolsdir
andproductdir
at line 245 and 249.I did this since setting the environment variable as mentioned in 2 (above) did not work.
May not be an elegant solution, but it worked.