Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

pydev and f2py

2008-07-21
2013-03-15
  • xavier siebert
    xavier siebert
    2008-07-21

    Hello folks,

    I have an application for which I import *.so modules resulting from the conversion from *.f fortran code with f2py.
    Even though the application find the modules properly, Pydev (1.3.18) flags an error for every variable/subroutine of these modules.

    For example, I have a module fitin.so, and in the python code I do -- given that the fortran code contains a subroutine called my_subroutine :

    import fitin
    fitin.my_subroutine()

    but Pydev would print this error:

    Undefined variable from import : my_subroutine()

    Is this clear ? How can I avoid pydev flagging this as an error ?
    And yes, the PYTHON PATH contains the path to fitin.so...

    Thanks,
    --X.

     
    • Fabio Zadrozny
      Fabio Zadrozny
      2008-07-21

      Are you configuring those to be in the project pythonpath or in the interpreter pythonpath? Actually, it should work without any special configuration. The problems on that may be:

      1. You're constantly changing the module, so, for each new token you may have to use ctrl+2 then 'kill' (this will restart the python shell that has been spawned to make a dir() in the module) -- restarting eclipse would also work for that.

      2. You're running eclipse from a shell that does not have the needed environment variables so that it can import that dll

      Basically, if from the same shell you launched eclipse you're able to start a python interpreter, import that dll (import fitin) and do a dir(fitin) and it returns the modules correctly, things should work...

      Cheers,

      Fabio

       
    • xavier siebert
      xavier siebert
      2008-07-22

      Fabio,

      Thanks for your quick response. I still did not resolve the problem though. Here is some more information, if it helps.

      > Are you configuring those to be in the project pythonpath or in the interpreter pythonpath?
      : I tried both and it does not change anything.

      > 1. You're constantly changing the module, so, for each new token you may have to use ctrl+2 then 'kill' (this will restart the python shell that has been spawned to make a dir() in the module) -- restarting > eclipse would also work for that.

      : the module does not change. restarting eclipse does not help.

      > 2. You're running eclipse from a shell that does not have the needed environment variables so that it can import that dll 
      > Basically, if from the same shell you launched eclipse you're able to start a python interpreter,
      > import that dll (import fitin) and do a dir(fitin) and it returns the modules correctly, things should work...

      : in the shell from which I start eclipse I can launch the python interpreter, do import fitin and dir(fitin) shows all what it should :

      >>> import fitin
      >>> dir(fitin)
      ['__doc__', '__file__', '__name__', '__version__', 'abrax', 'angkte', 'as_column_major_storage', 'cacao', 'cao', 'celdaez', 'cellez', 'cierre', 'corbyres', 'correl', 'dette', 'dimen', 'dimico', 'fitcorbyres', 'fitcorrel', 'fitin', 'fitswitch', 'fixmol', 'fsym', 'has_column_major_storage', 'iamin', 'initt', 'interpol', 'ioprg', 'lecfoq', 'lectab', 'maxou', 'ncsdat1', 'ncsdat2', 'ncsym', 'ortem', 'ortm', 'pro2mx', 'readalgo', 'redim', 'reso', 'rmx2e', 'rmx2p', 'rmxe', 'rmxp', 'rotra', 'rotran', 'starez', 'tables']

      But in eclipse any of the fitin subroutines shows as "unresolved variable from import".

      to try to figure out what happened, I created a new project directory and moved all my files in there.
      Strangely, at first it shows an error "unresolved import : fitin". When I clicked on the error to make the text editor jump to it, this error disappeared but turned into a bunch of "unresolved variable from import" for each subroutine from the fitin module...
      However, I can run the application from Eclipse, and I can even see the fitin variables/subroutines in the debugger, and they show up in the console if I add print dir(fitin) at the line where the error appears !

      I should have said I am running eclipse 3.2.2-5  (i.e. the latest package available for linux debian AFAIK). I saw another post today about the compatibility between eclipse 3.2 and pydev...
      Could this cause the problem ?

      Thanks,
      --X.

       
    • xavier siebert
      xavier siebert
      2008-07-25

      Hello,

      I think I found out where the problem was.
      The error occurs because I do something like this:
      try:
         import fitin
      except ImportError:
         try:
           import fitin2 as fitin
         except ImportError:
           print "Error importing fitin module"

      [the reason I do this "dirty" trick is that depending on the numpy version either fitin.so or fitin2.so can be imported...]

      It does not occur however if I do simply:
      try:
          import fitin
      except ImportError:
          print "Error importing fitin module"

      Well, sorry I bothered you guys.
      --X.