Duoyi Zhang
Duoyi Zhang

Reputation: 21

Error when using terminal to run mpi4py file

I want to run a mpi4py test file in terminal but it failed.

The operating system is mac and I am using anaconda2 with a python3. I installed mpi4py through anaconda environment. It works will on Pycharm, which also uses the anaconda environment.

The test code is:

from mpi4py import MPI
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
node_name = MPI.Get_processor_name() # get the name of the node
print ('Hello world from process %d at %s.' % (rank, node_name))

and I run this in terminal: mpirun -np 5 python test.py

the error message is :

Traceback (most recent call last): File "test.py", line 3, in from mpi4py import MPI ImportError: No module named mpi4py Traceback (most recent call last): File "test.py", line 3, in from mpi4py import MPI ImportError: No module named mpi4py Traceback (most recent call last): File "test.py", line 3, in from mpi4py import MPI ImportError: No module named mpi4py Traceback (most recent call last): File "test.py", line 3, in from mpi4py import MPI ImportError: No module named mpi4py Traceback (most recent call last): File "test.py", line 3, in from mpi4py import MPI

ImportError: No module named mpi4py

mpirun noticed that the job aborted, but has no info as to the process

that caused that situation.

Upvotes: 1

Views: 3142

Answers (2)

Liang
Liang

Reputation: 63

Try python3 instead of python in the command line.

mpirun -np 5 python3 test.py

Hope it works.

Upvotes: 3

Duoyi Zhang
Duoyi Zhang

Reputation: 21

figure it out...

Although I installed mpi4py through anaconda, and the default Python environment is python3.6 for anaconda, it did not installed mpi4py for the local environment.

After pip install mpi4py it works.

Still, I am a little confused why it works:( If someone happened to saw this post, please let me know the reason:)

Anyway... it is not that effective to use anaconda hehe.

Upvotes: 1

Related Questions