Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > f2py on windows tutorials

Reply
Thread Tools

f2py on windows tutorials

 
 
Flavio
Guest
Posts: n/a
 
      09-23-2006
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

 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      09-23-2006
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

 
Reply With Quote
 
 
 
 
Flavio
Guest
Posts: n/a
 
      09-26-2006
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


 
Reply With Quote
 
Robert Kern
Guest
Posts: n/a
 
      09-26-2006
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

 
Reply With Quote
 
Flavio
Guest
Posts: n/a
 
      09-26-2006
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


 
Reply With Quote
 
Robert Kern
Guest
Posts: n/a
 
      09-26-2006
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

 
Reply With Quote
 
Robert Kern
Guest
Posts: n/a
 
      09-26-2006
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

 
Reply With Quote
 
Flavio
Guest
Posts: n/a
 
      09-27-2006
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


 
Reply With Quote
 
Robert Kern
Guest
Posts: n/a
 
      09-27-2006
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

 
Reply With Quote
 
Flavio
Guest
Posts: n/a
 
      09-27-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
F2PY ?? Has anyone worked with the F2PY generator? Blubaugh, David A. Python 0 09-08-2008 10:04 PM
Re: [f2py] f2py problem Python 0 05-15-2007 03:23 PM
f2py on windows XP - "Unknown Switch"?? Sile Python 6 08-28-2006 01:31 PM
python-dev and setting up setting up f2py on Windows XP Sile Python 5 08-18-2006 08:13 AM
f2py error - windows xp (F2PY-2.43.239_1806) M. Faust Python 6 09-28-2004 12:42 AM



Advertisments