I have some simple Fortran .f90 codes. I want to compile it as DLL. everything is successful. I changed .DLL to .PYC . import pyc by python ,I got error.so what should I do?(I searched a lot in internet but all of them is about c or c++ not Fortran. I have both Python 2 and 3 installed. And having intel Fortran compiler and Visual Studio 2019 installed and MinGW installed.
math03.f90:
program example
implicit none
integer (kind=8), parameter :: n = 5000
integer (kind=8), dimension(0:n-1) :: primes
call get_primes(n,primes)
end program
subroutine get_primes(n,primes)
implicit none
integer (kind=8) :: n
integer (kind=8), dimension(0:n-1) :: primes
integer (kind=8) :: primes_found, prime_cand, ind
!primes(0) = 2
!primes_found = 1
!prime_cand = 3
do while (primes_found < n)
ind = 0
do while (ind < primes_found)
if (mod(prime_cand,primes(ind)) == 0) then
exit
else
ind = ind + 1
end if
end do
if (ind == primes_found) then
primes(primes_found) = prime_cand
primes_found = primes_found + 1
end if
prime_cand = prime_cand + 1
end do
end subroutine
intel fortran compiler:
UPDATE:
I use this command
ifort /dll math03.f90
so the result :
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.0.4.228 Build 20190417
Copyright (C) 1985-2019 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.21.27702.2
Copyright (C) Microsoft Corporation. All rights reserved.
-out:math03.dll
-dll
-implib:math03.lib
math03.obj
changing .dll to .pyc
python:
Python 2.7.16 (v2.7.16:413a49145e, Mar 4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import math03
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: Bad magic number in math03.pyc
another way I use this:
f2py -c math03.f90 -m primemod
I got this error:
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 "primemod" sources
f2py options: []
f2py:> c:\users\admin\appdata\local\temp\tmpyf3zf3\src.win-amd64-2.7\primemodmodule.c
creating c:\users\admin\appdata\local\temp\tmpyf3zf3\src.win-amd64-2.7
Reading fortran codes...
Reading file 'math03.f90' (format:free)
Post-processing...
Block: primemod
Block: example
Block: get_primes
Post-processing (stage 2)...
Building modules...
Building module "primemod"...
Constructing wrapper function "get_primes"...
get_primes(primes,[n])
Wrote C/API module "primemod" to file "c:\users\admin\appdata\local\temp\tmpyf3zf3\src.win-amd64-2.7\primemodmodule.c"
adding 'c:\users\admin\appdata\local\temp\tmpyf3zf3\src.win-amd64-2.7\fortranobject.c' to sources.
adding 'c:\users\admin\appdata\local\temp\tmpyf3zf3\src.win-amd64-2.7' to include_dirs.
copying c:\python27amd64\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\users\admin\appdata\local\temp\tmpyf3zf3\src.win-amd64-2.7
copying c:\python27amd64\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\users\admin\appdata\local\temp\tmpyf3zf3\src.win-amd64-2.7
build_src: building npy-pkg config files
running build_ext
customize MSVCCompiler
customize MSVCCompiler using build_ext
get_default_fcompiler: matching types: '['gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95', 'intelvem', 'intelem', 'flang']'
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
Could not locate executable DF
customize IntelItaniumVisualFCompiler
Could not locate executable efl
customize Gnu95FCompiler
Found executable C:\MinGW\bin\gfortran.exe
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gfortran.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --with-gmp=/mingw --with-mpfr=/mingw --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
customize Gnu95FCompiler
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gfortran.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --with-gmp=/mingw --with-mpfr=/mingw --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
customize Gnu95FCompiler using build_ext
building 'primemod' extension
compiling C sources
error: Unable to find vcvarsall.bat
got this error as mentioned:
error: Unable to find vcvarsall.bat
UPDATE:
Also I must say that https://symbols.hotell.kau.se/2016/12/15/python-fortran/ Does not work for me.
UPDATE #2
I make some changes , reinstall Visual Studio 2019 to 2017 ,reinstall Intel Parallel Studio 2019 for ifort
and add vcvarsall.bat
to PATH , uninstall MINGW gfortran
compiler ,Also edited my Fortran file and CMD command a little .
python -m numpy.f2py -c fib1.f -m fib1
so I get this error :
error: extension 'fib1' has Fortran sources but no Fortran compiler found
as details there is :
C:\Users\admin\Documents\GitHub\scikits.scattpy\src\math03\FIB>python -m numpy.f2py -c fib1.f -m fib1
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:\users\admin\appdata\local\temp\tmp5ah42b\src.win-amd64-2.7\fib1module.c
creating c:\users\admin\appdata\local\temp\tmp5ah42b\src.win-amd64-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:\users\admin\appdata\local\temp\tmp5ah42b\src.win-amd64-2.7\fib1module.c"
adding 'c:\users\admin\appdata\local\temp\tmp5ah42b\src.win-amd64-2.7\fortranobject.c' to sources.
adding 'c:\users\admin\appdata\local\temp\tmp5ah42b\src.win-amd64-2.7' to include_dirs.
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\users\admin\appdata\local\temp\tmp5ah42b\src.win-amd64-2.7
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\users\admin\appdata\local\temp\tmp5ah42b\src.win-amd64-2.7
build_src: building npy-pkg config files
running build_ext
customize MSVCCompiler
customize MSVCCompiler using build_ext
get_default_fcompiler: matching types: '['gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95', 'intelvem', 'intelem', 'flang']'
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
Could not locate executable DF
customize IntelItaniumVisualFCompiler
Could not locate executable efl
customize Gnu95FCompiler
Could not locate executable gfortran
Could not locate executable f95
customize G95FCompiler
Could not locate executable g95
customize IntelEM64VisualFCompiler
customize IntelEM64TFCompiler
Could not locate executable efort
Could not locate executable efc
customize PGroupFlangCompiler
don't know how to compile Fortran code on platform 'nt'
warning: build_ext: f77_compiler=None is not available.
building 'fib1' extension
error: extension 'fib1' has Fortran sources but no Fortran compiler found
UPDATE #3: as all the conditions in Python Error : File ... spherical.py... import f_utils...ImportError: No module named f_utils and specially in It's UPDATE #1
,f2py
works successfully .