[Trilinos-Users] [EXTERNAL] Cannot import PyTrilinos.NOX

Bill Spotz wfspotz at sandia.gov
Wed Jun 19 08:50:54 MDT 2013


Jonathan,

What version of SWIG are you using?  The latest, version 2.0.9, has this nested module import problem.  Version 2.0.8 works, as does the developers repository.

-Bill

On Jun 19, 2013, at 7:09 AM, Jonathan Guyer wrote:

> Attempting to run the PyTrilinos NOX example fails:
> 
> {{{
> $ python exNOX_1Dfdm.py 
> Traceback (most recent call last):
>  File "exNOX_1Dfdm.py", line 80, in <module>
>    NOX       = fromPyTrilinosImport('NOX'      , options.testharness)
>  File "/Users/guyer/.virtualenvs/trilinos/build/trilinos-11.2.3-Source/TEST1/packages/PyTrilinos/example/testutil.py", line 86, in fromPyTrilinosImport
>    PyTrilinosPkg = __import__(fullname, globals, locals)
>  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyTrilinos/NOX/__init__.py", line 488, in <module>
>    import NestedEpetra as Epetra
>  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyTrilinos/NOX/NestedEpetra/__init__.py", line 2777, in <module>
>    class FiniteDifference(PyTrilinos.Epetra.RowMatrix,PyTrilinos.NOX.NestedEpetra.Interface.Jacobian,PyTrilinos.NOX.NestedEpetra.Interface.Preconditioner):
> AttributeError: 'module' object has no attribute 'NOX'
> }}}
> 
> The problem is a circular import because PyTrilinos/NOX/__init__.py does `import NestedEpetra as Epetra` 
> and PyTrilinos/NOX/NestedEpetra/__init__.py does `import PyTrilinos.NOX.NestedEpetra.Interface`
> but PyTrilinos.NOX isn't finished importing, yet, so the PyTrilinos package doesn't have a NOX module at this point.
> 
> PyTrilinos in 10.6.4 (before renaming PyTrilinos.NOX.Epetra to PyTrilinos.NOX.NestedEpetra) just did a relative `import Interface`. I know that relative imports are discouraged, but may be the only choice here.
> 
> Manually changing PyTrilinos.NOX.NestedEpetra.Interface to Interface througout PyTrilinos/NOX/NestedEpetra/__init__.py does resolve the problem and the example runs successfully, but I don't begin to understand the CMake `.i` witchcraft well enough to see where to patch the source code.
> _______________________________________________
> Trilinos-Users mailing list
> Trilinos-Users at software.sandia.gov
> http://software.sandia.gov/mailman/listinfo/trilinos-users

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: wfspotz at sandia.gov **








More information about the Trilinos-Users mailing list