1

I'm trying to compile some project I've found on the web. the project is wrapping some Fortran code into python object.

The author of that project wrote I need to run the setup.py file.

I've done that. It contains the following piece of code:

  ext = Extension(name = "GaussianFitter._Fitter",
                sources = ["GaussianFitter/src/lmdif.f",
                           "GaussianFitter/src/splev.f",
                           "GaussianFitter/src/gaussian.f90"],

and obviously all these "f" files are existing. When I install that setup.py file it seams to do some job succesfully but the first line in the script which uses that _Fitter:

import _Fitter

doesn't work.

I'm newby with python, and have no experiment with Fortran at all, so please forgive my ignorance.

Edit: project available here:

https://github.com/ardiloot/GaussianFitter

Thanks!

6
  • 1
    What do you mean by “it doesn’t work”? Does it throw an error? Which? Commented Dec 24, 2018 at 14:19
  • Hi - I'm working with pyCharm and getting a red line under the import. If trying to run- I get a cannot import error. Thanks Commented Dec 24, 2018 at 14:24
  • 1
    Is there some error message? Please find some drtails. Commented Dec 24, 2018 at 15:10
  • Thanks - yes, finally got something. I probably failed to install mingw, I ran now the install file using parameter "install" on self.ld_version which is "none_type" which I guess means it couldn't find the compiler... Commented Dec 24, 2018 at 15:21
  • @RodrigoRodrigues - I'm using following line: from numpy.distutils.core import setup, and then calling the setup function. Do you know how to specify which compiler to use? where it is etc? some link? Thanks! Commented Dec 24, 2018 at 15:29

1 Answer 1

1

Finally made it, so here's my for-begginers tutorial:

note - since it's for beginners - it sets all in the global scope.

  1. install mingw32 from: http://www.mingw.org/ Add it's bin path to system PATH.
  2. add a setup.cfg file containing the following text:

    [build]

    compiler=mingw32

locate it in %pythondir%\Lib\distutils

  1. since setup.py file contains links to .c or .f files (c++/fortran/c) in order to make command (python setup.py install) be able to locate these files - run the command when working directory (i.e. cd c:....\) is set.

  2. Ignore red error line in code when you import that module. It is in the LIB directory, just try to run...

EDIT:

If still not managing to import the already built f files - building it in the following way might help:

python setup.py build_ext --inplace

which generates an object (*.pyd), this helped me after it, for any reason, stopped working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.