Error calling pylith within python - _mpi dependency missing from pythia?

Hi everyone-

I am working on a project that calls pylith from within a larger python framework instead of the command line, but have run into some issues getting pylith to run under these circumstances. For context, I am running 4.0.0 installed from the .tar file on a WSL2 virtual machine running Ubuntu.

Within the installation, I have found the RunnerApp package and its demonstration in, both of which should do what I’m trying to do. Their file paths are:


Unfortunately, when I try to import the RunnerApp functions into a python script (after running of course), I get the following error message:

from pylith.apps.RunnerApp import RunnerApp
Traceback (most recent call last):
File “”, line 1, in
File “/home/jalbr/opt/Pylith-4.0.0/lib/python3.10/site-packages/pylith/apps/”, line 19, in
from pylith.apps.PyLithApp import PyLithApp
File “/home/jalbr/opt/Pylith-4.0.0/lib/python3.10/site-packages/pylith/apps/”, line 14, in
from .PetscApplication import PetscApplication
File “/home/jalbr/opt/Pylith-4.0.0/lib/python3.10/site-packages/pylith/apps/”, line 15, in
from pythia.mpi import Application
File “/home/jalbr/opt/Pylith-4.0.0/lib/python3.10/site-packages/pythia/mpi/”, line 14, in
from _mpi import *
ModuleNotFoundError: No module named ‘_mpi’

This error seems to run through a chain of dependencies to the pythia module, which seems to be missing either another installed module or a local file “_mpi”. Would anyone know how to restore this dependency, or otherwise fix this issue? Alternatively, is there a better or more direct way of calling pylith from within python?

Thank you so much!

PyLith applications do not run using the normal Python interpreter. They use a special version of the interpreter that is MPI aware, called nemesis. You will see that in all of the Python scripts included with PyLith (including the pylith script itself), the first line is #!/usr/bin/env nemesis rather than #!/usr/bin/env python.

If you want to run the PyLith application, then you need to invoke your Python script with nemesis. You ran run nemesis or change the first line of your script to #!/usr/bin/env nemesis as we do in our Python scripts.