6

I'm a student and I'm using python for the first time.

Currently I'm using Xubuntu 19.10 on a virtual machine, I checked the python and mpi4py installation.

My professor of "Parallel programming" gave me this simple python code.

from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
print ("hello world from process ", rank)

I'm trying to run it but it doesn't works and I don't know how to fix it. When I try to execute, I receive this statement for each of the 4 process:

$ mpirun -n 4 python3 hello.py
Traceback (most recent call last):
     File "hello.py", line 3, in <module>
     from mpi4py import MPI
ModuleNotFoundError: No module named 'mpi4py'
2
  • Install mpi4py? Commented Nov 25, 2019 at 13:27
  • you need to install mpi4py (hence the error in from mpi4py import MPI). Try pip install mpi4py Commented Nov 25, 2019 at 13:28

4 Answers 4

6

you can install mpi4py via pip in your terminal

pip install mpi4py

or

 pip3 install mpi4py
Sign up to request clarification or add additional context in comments.

4 Comments

If I try it, then I receive Requirement already satisfied: mpi4py in /usr/lib/python2.7/dist-packages (3.0.2)
You must then try pip3 install mpi4py
In your case the pip is trying to install to python2.7 but you are trying to run you code with python3
The issue is because python2 has the package but python3 doesnt
6

If you are using 3.x version of python, could you try installing using

pip3 install mpi4py

Maybe you tried installing using just pip, and it might have installed to the 2.7 version of your python.

pip is for versions less than 3. pip3 is for versions 3.x

Comments

1

for Python3+: pip3 install mpi4py and for python lesser version: pip install mpi4py

Problem is the package is not installed

Comments

0

mpi4py is a package that depends on your mpi implementation. You need to install a MPI wrapper (i.e. OpenMpi). Then, you can echo $mpicc and make sure the path is correct. With these, you should be able to install mpi4py correctly with pip, pip install mpi4py You can use pip or pip3 as long as this commands point to the wanted distribution of python. pip --version

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.