2013-06-05 9 views
12

Sto tentando di creare un'estensione Python dal sorgente Fortran usando lo script f2py.py di Numpy. Sto seguendo i passaggi da http://www.scipy.org/F2PY_Windows (web archive). Il mio sistema è Windows 7 64-bit e uso principalmente Python 2.7.3 [MSC v.1500 64 bit (AMD64)]. Ho Numpy-MKL 1.7.1, da http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpyCreazione di estensioni Python a 64 bit con f2py su Windows

Ecco che cosa ho provato:

  1. Scegliere un compilatore Fortran. Dato che sto usando Python 64 bit, è richiesto un compilatore Fortran a 64 bit. Da MinGW-w64, ho provato alcune delle build personali.
  2. Aprire una nuova cmd.exe shell, e modificare il percorso in cui ho estratto i compilatori GCC, vale a dire:
    • set PATH=%PATH%;c:\gnu\mingw64\bin
    • set C_INCLUDE_PATH=C:\gnu\mingw64\include
  3. provare la build f2py.py con questo comando:

    C:\Python27\python.exe C:\Python27\Scripts\f2py.py -c --fcompiler=gnu95 --compiler=mingw32 -lmsvcr90 -m foo foo.f90

L'uscita è (rimozione di linee di rumore a <--snip-->):

running build 
<--snip--> 
Reading fortran codes... 
     Reading file 'foo.f90' (format:free) 
Post-processing... 
     Block: foo 
         Block: hello 
Post-processing (stage 2)... 
Building modules... 
     Building module "foo"... 
       Constructing wrapper function "hello"... 
        hello() 
     Wrote C/API module "foo" to file "c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7\foomodule.c" 
    adding 'c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7\fortranobject.c' to sources. 
    adding 'c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7' to include_dirs. 
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7 
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7 
build_src: building npy-pkg config files 
running build_ext 
Looking for python27.dll 
Building import library (arch=AMD64): "C:\Python27\libs\libpython27.a" (from C:\Windows\system32\python27.dll) 
Building msvcr library: "C:\Python27\libs\libmsvcr90.a" (from C:\Windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcr90.dll) 
Cannot build msvcr library: "msvcr90d.dll" not found 
customize Mingw32CCompiler 
customize Mingw32CCompiler using build_ext 
customize Gnu95FCompiler 
Found executable c:\gnu\mingw64\bin\gfortran.exe 
Found executable c:\gnu\mingw64\bin\gfortran.exe 
Traceback (most recent call last): 
    File "C:\Python27\Scripts\f2py.py", line 24, in <module> 
    main() 
<--snip--> 
    File "C:\Python27\lib\site-packages\numpy\distutils\fcompiler\gnu.py", line 331, in get_libraries 
    raise NotImplementedError("Only MS compiler supported with gfortran on win64") 
NotImplementedError: Only MS compiler supported with gfortran on win64 

Si noti che la prima volta che viene eseguito, tre nuovi file sono costruiti in C:\Python27\libs:

  • libmsvcr90.a
  • libpython27.a
  • python27.def

Devo installare qualcos'altro? Devo fornire altre opzioni a f2py? Più in generale, è possibile creare un'estensione per MSVC-build Python dai compilatori GNU?

risposta

8

Sembra che la soluzione sia solo commentare la riga delle eccezioni. Vedi questo blog post.

+1

Sembra funzionare. Inoltre, ho dovuto rimuovere un flag '-lmsvcr90' su f2py. –

+0

Lo stesso per me, tranne che non stavo eseguendo direttamente f2py, era chiamato internamente tramite distutils numpy. Questo post mi ha aiutato (e noto di cancellare il file 'libmsvcr90.a' che è stato generato): http://mechaos.de/wordpress/?p=303#comment-169 –

1

ho avuto l'errore simile quando si tenta di installare ggplot con

pip install -U ggplot 

La soluzione è stata trovata qui: https://github.com/obspy/obspy/wiki/Installation-via-Anaconda

Anaconda per Windows viene fornito con C e Fortran compilatori, tuttavia compilazione su un Windows a 64 bit potrebbe richiedere una piccola patch modificando il numero di linea . 331 in AnacondaInstallDir \ Lib \ site-packages \ numpy \ distutils \ fcompiler \ gnu.py per passare #raise NotImplementedError ("Solo MS compilatore supportato con gfortran su win64").

0

questo dovrebbe essere fissato in una versione futura, un discussed e changed.

Sembra che questa modifica non sia stata apportata al ramo di manutenzione 1.9.x, ma nell'albero master e in qualsiasi versione sia successiva.

Problemi correlati