python - Kan ikke importere modul efter kompilering f2py

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg forsøger at bruge f2py (for første gang) til at kalde en Fortran subrutine inden for python. Rutinen er meget grundlæggende, da det kun er at se, hvordan f2py virker.


subroutine test\_f2(a,b)
    implicit none
    real*8 :: a,b
    ! f2py  intent ( in ) a
    ! f2py  intent ( out ) b    
    b = a +2d0
end subroutine


Den opsatte fil er i formularen:


from numpy.distutils.core import Extension

ext1 = Extension(name = 'chosen\_name',
       sources = ['fortran\_file\_name.f90'])

if \_\_name\_\_ == "\_\_main\_\_":
    from numpy.distutils.core import setup
    setup(name = 'pp\_name',
        ext\_modules = [ext1]


Endelig kommer jeg fra kommandolinjen


python setup\_file\_name.py build


Nedenfor er et resumé af, hvad jeg får. Jeg får ikke en fejlmeddelelse i slutningen (selvom jeg får nogle advarsler), og der oprettes en build-mappe i arbejdsmappen.


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 "chosen\_name" sources
f2py options: []
f2py:> buildsrc.win-amd64-3.6chosen\_name.c
creating build
creating buildsrc.win-amd64-3.6
Reading fortran codes...
    Reading file 'fortran\_file\_name.f90' (format:free)
Post-processing...
    Block: chosen\_name
    Block: test\_f2
 Post-processing (stage 2)...
 Building modules...
    Building module "chosen\_name"...
            Constructing wrapper function "test\_f2"...
              test\_f2(a,b)
    Wrote C/API module "chosen\_name" to file "buildsrc.win-amd64-3.6chosen\_namemodule.c"
   adding 'buildsrc.win-amd64-3.6uildsrc.win-amd64-3.6fortranobject.c' to sources.
   adding 'buildsrc.win-amd64-3.6uildsrc.win-amd64-3.6' to include\_dirs.
   creating buildsrc.win-amd64-3.6uild
   creating buildsrc.win-amd64-3.6uildsrc.win-amd64-3.6
   copying C:UsersBertrandAnaconda3libsite-packages
umpyf2pysrcfortranobject.c -> buildsrc.win-amd64-3.6uildsrc.win-amd64-3.6
   copying C:UsersBertrandAnaconda3libsite-packages
umpyf2pysrcfortranobject.h -> buildsrc.win-amd64-3.6uildsrc.win-amd64-3.6
   build\_src: building npy-pkg config files
   running build\_ext
   No module named 'numpy.distutils.\_msvccompiler' in numpy.distutils, trying from distutils
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
[...]
building 'chosen\_name' extension
compiling C sources
creating build	emp.win-amd64-3.6Releaseuild
creating build	emp.win-amd64-3.6Releaseuildsrc.win-amd64-3.6
creating build	emp.win-amd64-3.6Releaseuildsrc.win-amd64-3.6uild
creating build	emp.win-amd64-3.6Releaseuildsrc.win-amd64-3.6uildsrc.win-amd64-3.6
C:Program Files (x86)Microsoft Visual Studio 14.0...
[...]


Problemet er imidlertid, at jeg ikke kan importere modulet, som skulle have været oprettet i mappen:


ModuleNotFoundError: No module named 'chosen\_name'


Jeg har set på flere tidligere emner med nogle der er relaterede, men jeg kunne ikke løse dette problem. Enhver ide?


Andre oplysninger: Windows 10, Python 3.6 Anaconda distribution, gfortran installeret.

Bedste reference