f2py on windows tutorials

F

Flavio

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
 
R

Robert Kern

Flavio said:
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
 
F

Flavio

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
 
R

Robert Kern

Flavio said:
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
 
F

Flavio

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 said:
Flavio said:
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
 
R

Robert Kern

Flavio said:
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
 
R

Robert Kern

Robert said:
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
 
F

Flavio

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...
 
R

Robert Kern

Flavio said:
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
 
F

Flavio

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 said:
Flavio said:
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
 
F

Flavio

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 said:
Flavio said:
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
 
R

Robert Kern

Flavio said:
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
 
R

Robert Kern

Flavio said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top