[Trilinos-Users] Cannot import PyTrilinos.NOX
Jonathan Guyer
guyer at nist.gov
Wed Jun 19 07:09:57 MDT 2013
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.
More information about the Trilinos-Users
mailing list