cannot import python module when using mpiexec

Issue #168 resolved
Ivan00 created an issue

I have a puzzling problem when using mpi4py, and I use a simple program to verify that mpi4py is available.

# test.py
from mpi4py import MPI
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
node_name = MPI.Get_processor_name()
print('Hello world from process %d at %s.' % (rank, node_name))

When I type the following command, it works:

python test.py
# Hello world from process 0 at 75c44e7165d6.

However, when I use mpiexec, I get the following error:

mpiexec -n 4 python test.py
# ImportError: No module named 'mpi4py'

When I try to import other Python modules, the program will also report an error, like ImportError: No module named 'numpy'However, these modules can be used when using python xxx.py directly.

I checked my Python and pip versions carefully to make sure they were correct. My operating system is Ubuntu, and I've never had this problem with mpi4py on many other similar servers. What are the possible causes of this error? thanks a lot!

Comments (3)

  1. Lisandro Dalcin

    This is an mpiexec issue, and not mpi4py’s fault. Do you have mpi4py installed in some standard location? Are you setting the PYTHONPATH environment variable? If yes, then maybe mpiexec is not propagating it down. Also, double check that your mpiexec comes from the package that was used to build mpi4py. Ubuntu is notorious for messing up openmpi/mpich installs with the alternatives system they use, and they have not fixed it for years.

  2. Ivan00 reporter

    Thank you for your quick reply! Now the problem has been solved.

    At your prompt, I usempiexec -n 4 python --version and find It was misdirected to Python 2.7. Mpiexec works well after using update-alternatives to change the python version.

  3. Log in to comment