f2py on windows tutorials

Discussion in 'Python' started by Flavio, Sep 23, 2006.

  1. Flavio

    Flavio Guest

    Hello,

    Compiling f2py extensions in Linux is a trivial task, You can even
    automate it with distutils. Now, in a Windows machine this does not
    seem to be an easy task. At least, I could not find any decent tutorial
    on how to do it.

    Is there a way to do this? Can some one point me to a tutorial.,
    please?

    I have tried some approaches: mingw, xmingw (cross-compiling from
    Linux) and Python enthought edition (which is supposed to come
    preconfigured to enable people to use Scipy tools, such as f2py)
    Withouth success.

    Anyone out there knows how to do this? Anyone from the Scipy dev team
    care to document it?

    Flávio
    Flavio, Sep 23, 2006
    #1
    1. Advertising

  2. Flavio

    Robert Kern Guest

    Flavio wrote:
    > Hello,
    >
    > Compiling f2py extensions in Linux is a trivial task, You can even
    > automate it with distutils. Now, in a Windows machine this does not
    > seem to be an easy task. At least, I could not find any decent tutorial
    > on how to do it.
    >
    > Is there a way to do this? Can some one point me to a tutorial.,
    > please?
    >
    > I have tried some approaches: mingw, xmingw (cross-compiling from
    > Linux) and Python enthought edition (which is supposed to come
    > preconfigured to enable people to use Scipy tools, such as f2py)
    > Withouth success.
    >
    > Anyone out there knows how to do this? Anyone from the Scipy dev team
    > care to document it?


    <shrug> It's worked fine for me using Enthon (which comes with mingw and g77,
    things you will need at minimum).

    What versions of Enthon and f2py are you using?
    What exactly did you try?
    What errors are you seeing?
    How are you trying to compile your modules, i.e. with just the f2py command or
    are you building a setup.py file?
    Did you pass "--compiler=mingw --fcompiler=gnu" to your build command?

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Sep 23, 2006
    #2
    1. Advertising

  3. Flavio

    Flavio Guest

    Its been a while since i Tried this and right now I have no access to a
    windows
    machine to try it and show you the error messages I was getting.

    I was using the latest version of Python Enthouhgt edition. But I was
    trying to compile the fortran code directly with f2py.

    What I would like to have is a setup.py tailored to compile an f2py
    extension on windows. Have you got one of these? if so please send it
    to me and I can certainly figure out the rest.

    thanks,

    Flavio

    Robert Kern wrote:
    > Flavio wrote:
    > > Hello,
    > >
    > > Compiling f2py extensions in Linux is a trivial task, You can even
    > > automate it with distutils. Now, in a Windows machine this does not
    > > seem to be an easy task. At least, I could not find any decent tutorial
    > > on how to do it.
    > >
    > > Is there a way to do this? Can some one point me to a tutorial.,
    > > please?
    > >
    > > I have tried some approaches: mingw, xmingw (cross-compiling from
    > > Linux) and Python enthought edition (which is supposed to come
    > > preconfigured to enable people to use Scipy tools, such as f2py)
    > > Withouth success.
    > >
    > > Anyone out there knows how to do this? Anyone from the Scipy dev team
    > > care to document it?

    >
    > <shrug> It's worked fine for me using Enthon (which comes with mingw and g77,
    > things you will need at minimum).
    >
    > What versions of Enthon and f2py are you using?
    > What exactly did you try?
    > What errors are you seeing?
    > How are you trying to compile your modules, i.e. with just the f2py command or
    > are you building a setup.py file?
    > Did you pass "--compiler=mingw --fcompiler=gnu" to your build command?
    >
    > --
    > Robert Kern
    >
    > "I have come to believe that the whole world is an enigma, a harmless enigma
    > that is made terrible by our own mad attempt to interpret it as though it had
    > an underlying truth."
    > -- Umberto Eco
    Flavio, Sep 26, 2006
    #3
  4. Flavio

    Robert Kern Guest

    Flavio wrote:
    > Its been a while since i Tried this and right now I have no access to a
    > windows
    > machine to try it and show you the error messages I was getting.
    >
    > I was using the latest version of Python Enthouhgt edition. But I was
    > trying to compile the fortran code directly with f2py.
    >
    > What I would like to have is a setup.py tailored to compile an f2py
    > extension on windows. Have you got one of these? if so please send it
    > to me and I can certainly figure out the rest.



    from numpy.distutils.core import setup, Extension

    setup(name='something',
    ext_modules=[Extension('my_subroutines',
    sources=['wrapper.pyf', 'lib1.f', 'lib2.f'],
    )],
    )

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Sep 26, 2006
    #4
  5. Flavio

    Flavio Guest

    Thank you Robert,

    I was surprised that the setup.py was virtually identical to the one I
    use for Linux. However I was not at all surprised when it didn't work.
    ;-)

    It complains it can't find msvc:

    No module named msvccompiler in numpy.distutils, trying from
    distutils..
    error: the .NET Framework SDK needs to be installed before building
    extensions for Python.

    any further help will be greatly appreciated...

    Thanks again,

    Flávio

    Robert Kern wrote:
    > Flavio wrote:
    > > Its been a while since i Tried this and right now I have no access to a
    > > windows
    > > machine to try it and show you the error messages I was getting.
    > >
    > > I was using the latest version of Python Enthouhgt edition. But I was
    > > trying to compile the fortran code directly with f2py.
    > >
    > > What I would like to have is a setup.py tailored to compile an f2py
    > > extension on windows. Have you got one of these? if so please send it
    > > to me and I can certainly figure out the rest.

    >
    >
    > from numpy.distutils.core import setup, Extension
    >
    > setup(name='something',
    > ext_modules=[Extension('my_subroutines',
    > sources=['wrapper.pyf', 'lib1.f', 'lib2.f'],
    > )],
    > )
    >
    > --
    > Robert Kern
    >
    > "I have come to believe that the whole world is an enigma, a harmless enigma
    > that is made terrible by our own mad attempt to interpret it as though it had
    > an underlying truth."
    > -- Umberto Eco
    Flavio, Sep 26, 2006
    #5
  6. Flavio

    Robert Kern Guest

    Flavio wrote:
    > Thank you Robert,
    >
    > I was surprised that the setup.py was virtually identical to the one I
    > use for Linux. However I was not at all surprised when it didn't work.
    > ;-)
    >
    > It complains it can't find msvc:
    >
    > No module named msvccompiler in numpy.distutils, trying from
    > distutils..
    > error: the .NET Framework SDK needs to be installed before building
    > extensions for Python.
    >
    > any further help will be greatly appreciated...


    From my previous post:
    Did you pass "--compiler=mingw --fcompiler=gnu" to your build command?

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Sep 27, 2006
    #6
  7. Flavio

    Robert Kern Guest

    Robert Kern wrote:
    > Flavio wrote:
    >> Thank you Robert,
    >>
    >> I was surprised that the setup.py was virtually identical to the one I
    >> use for Linux. However I was not at all surprised when it didn't work.
    >> ;-)
    >>
    >> It complains it can't find msvc:
    >>
    >> No module named msvccompiler in numpy.distutils, trying from
    >> distutils..
    >> error: the .NET Framework SDK needs to be installed before building
    >> extensions for Python.
    >>
    >> any further help will be greatly appreciated...

    >
    > From my previous post:
    > Did you pass "--compiler=mingw --fcompiler=gnu" to your build command?


    More specifically:

    python setup.py build_ext --compiler=mingw --fcompiler=gnu

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Sep 27, 2006
    #7
  8. Flavio

    Flavio Guest

    Ok,

    I tried that and it seems we are making progress

    so here is my command:

    python setup.py build_ext --compiler=mingw32 --fcompiler=gnu

    Now it is complaining about my pyf!!

    error: unknown file type '.pyf'

    here is my setup .py:

    import setuptools, os
    from numpy.distutils.core import setup, Extension

    #Configuring Build
    libs=[];libdirs=[];f2pyopts=[]
    if os.name == 'nt':
    f2pyopts.extend(["--compiler=mingw32","--fcompiler=gnu"])



    flib = Extension(name='flib',
    libraries=libs,
    library_dirs=libdirs,
    f2py_options=f2pyopts,

    sources=['model-builder/Bayes/flib.f','model-builder/Bayes/flib.pyf',]
    )
    etc...
    >
    > More specifically:
    >
    > python setup.py build_ext --compiler=mingw --fcompiler=gnu
    >
    > --
    > Robert Kern
    >
    > "I have come to believe that the whole world is an enigma, a harmless enigma
    > that is made terrible by our own mad attempt to interpret it as though it had
    > an underlying truth."
    > -- Umberto Eco
    Flavio, Sep 27, 2006
    #8
  9. Flavio

    Robert Kern Guest

    Flavio wrote:
    > Ok,
    >
    > I tried that and it seems we are making progress
    >
    > so here is my command:
    >
    > python setup.py build_ext --compiler=mingw32 --fcompiler=gnu
    >
    > Now it is complaining about my pyf!!
    >
    > error: unknown file type '.pyf'
    >
    > here is my setup .py:
    >
    > import setuptools, os
    > from numpy.distutils.core import setup, Extension
    >
    > #Configuring Build
    > libs=[];libdirs=[];f2pyopts=[]
    > if os.name == 'nt':
    > f2pyopts.extend(["--compiler=mingw32","--fcompiler=gnu"])


    These don't belong here. If you don't want to type them in at the command line,
    put them in a setup.cfg file next to your setup.py:


    [build_ext]
    compiler=mingw
    fcompiler=gnu


    (Note: "mingw", not "mingw32"!)

    > flib = Extension(name='flib',
    > libraries=libs,
    > library_dirs=libdirs,
    > f2py_options=f2pyopts,
    >
    > sources=['model-builder/Bayes/flib.f','model-builder/Bayes/flib.pyf',]


    The .pyf file needs to come first.

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Sep 27, 2006
    #9
  10. Flavio

    Flavio Guest

    Hi Robert,

    Putting the .pyf first didn't do any good. I still get the same error
    message of unknown file type

    However when I try to compile with f2py, all works perfectly! here is
    the command I used:

    f2py -c flib.pyf flib.f --compiler=mingw32 --fcompiler=gnu

    Note: if I use mingw instead of mingw32 it does not work!!

    So all that remains now is to be able to do it from the setup.py...

    thanks again...

    Robert Kern wrote:
    > Flavio wrote:
    > > Ok,
    > >
    > > I tried that and it seems we are making progress
    > >
    > > so here is my command:
    > >
    > > python setup.py build_ext --compiler=mingw32 --fcompiler=gnu
    > >
    > > Now it is complaining about my pyf!!
    > >
    > > error: unknown file type '.pyf'
    > >
    > > here is my setup .py:
    > >
    > > import setuptools, os
    > > from numpy.distutils.core import setup, Extension
    > >
    > > #Configuring Build
    > > libs=[];libdirs=[];f2pyopts=[]
    > > if os.name == 'nt':
    > > f2pyopts.extend(["--compiler=mingw32","--fcompiler=gnu"])

    >
    > These don't belong here. If you don't want to type them in at the command line,
    > put them in a setup.cfg file next to your setup.py:
    >
    >
    > [build_ext]
    > compiler=mingw
    > fcompiler=gnu
    >
    >
    > (Note: "mingw", not "mingw32"!)
    >
    > > flib = Extension(name='flib',
    > > libraries=libs,
    > > library_dirs=libdirs,
    > > f2py_options=f2pyopts,
    > >
    > > sources=['model-builder/Bayes/flib.f','model-builder/Bayes/flib.pyf',]

    >
    > The .pyf file needs to come first.
    >
    > --
    > Robert Kern
    >
    > "I have come to believe that the whole world is an enigma, a harmless enigma
    > that is made terrible by our own mad attempt to interpret it as though it had
    > an underlying truth."
    > -- Umberto Eco
    Flavio, Sep 27, 2006
    #10
  11. Flavio

    Flavio Guest

    Hi Robert,

    Good News,

    I tried creating the setup.cfg as you suggested and ran

    python setup.py bdist_wininst
    and
    python setup.py bdist_egg

    both of them worked perfectly!!! compiled my Fortran extension, and
    packed it up for distribution.
    I have since installed and tested and it even works! isn't this great?

    thanks for all the help you provided. I couldn't have done it without
    it.

    Cheers,

    Flávio
    Robert Kern wrote:
    > Flavio wrote:
    > > Ok,
    > >
    > > I tried that and it seems we are making progress
    > >
    > > so here is my command:
    > >
    > > python setup.py build_ext --compiler=mingw32 --fcompiler=gnu
    > >
    > > Now it is complaining about my pyf!!
    > >
    > > error: unknown file type '.pyf'
    > >
    > > here is my setup .py:
    > >
    > > import setuptools, os
    > > from numpy.distutils.core import setup, Extension
    > >
    > > #Configuring Build
    > > libs=[];libdirs=[];f2pyopts=[]
    > > if os.name == 'nt':
    > > f2pyopts.extend(["--compiler=mingw32","--fcompiler=gnu"])

    >
    > These don't belong here. If you don't want to type them in at the command line,
    > put them in a setup.cfg file next to your setup.py:
    >
    >
    > [build_ext]
    > compiler=mingw
    > fcompiler=gnu
    >
    >
    > (Note: "mingw", not "mingw32"!)
    >
    > > flib = Extension(name='flib',
    > > libraries=libs,
    > > library_dirs=libdirs,
    > > f2py_options=f2pyopts,
    > >
    > > sources=['model-builder/Bayes/flib.f','model-builder/Bayes/flib.pyf',]

    >
    > The .pyf file needs to come first.
    >
    > --
    > Robert Kern
    >
    > "I have come to believe that the whole world is an enigma, a harmless enigma
    > that is made terrible by our own mad attempt to interpret it as though it had
    > an underlying truth."
    > -- Umberto Eco
    Flavio, Sep 27, 2006
    #11
  12. Flavio

    Robert Kern Guest

    Flavio wrote:
    > Hi Robert,
    >
    > Putting the .pyf first didn't do any good. I still get the same error
    > message of unknown file type


    That's ... odd. It works perfectly fine for scipy, and yet I can't get it to
    work, either, standing alone.

    > However when I try to compile with f2py, all works perfectly! here is
    > the command I used:
    >
    > f2py -c flib.pyf flib.f --compiler=mingw32 --fcompiler=gnu
    >
    > Note: if I use mingw instead of mingw32 it does not work!!


    My apologies, you are right.

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Sep 27, 2006
    #12
  13. Flavio

    Robert Kern Guest

    Flavio wrote:
    > Hi Robert,
    >
    > Good News,
    >
    > I tried creating the setup.cfg as you suggested and ran
    >
    > python setup.py bdist_wininst
    > and
    > python setup.py bdist_egg
    >
    > both of them worked perfectly!!! compiled my Fortran extension, and
    > packed it up for distribution.
    > I have since installed and tested and it even works! isn't this great?
    >
    > thanks for all the help you provided. I couldn't have done it without
    > it.


    I found out why you were getting the probel with .pyf files before. The
    dependency management between commands is a bit wonky, so in order to use .pyf
    files, you need to run the build_src command explicitly before build_ext (or
    *just* use build or one of the bdist_*).

    python setup.py build_src build_ext --compiler=mingw32 build
    python setup.py build
    python setup.py bdist_egg

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Sep 27, 2006
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. M. Faust
    Replies:
    6
    Views:
    509
    Robert Kern
    Sep 28, 2004
  2. Sile
    Replies:
    5
    Views:
    691
  3. Sile
    Replies:
    6
    Views:
    438
  4. Guest

    Re: [f2py] f2py problem

    Guest, May 15, 2007, in forum: Python
    Replies:
    0
    Views:
    583
    Guest
    May 15, 2007
  5. Blubaugh, David A.

    F2PY ?? Has anyone worked with the F2PY generator?

    Blubaugh, David A., Sep 8, 2008, in forum: Python
    Replies:
    0
    Views:
    260
    Blubaugh, David A.
    Sep 8, 2008
Loading...

Share This Page