Downloading mpi4py for Fedora

I was trying to download mpi4py for fedora and I have encountered with this problem

          2 | #include <mpi.h>
            |          ^~~~~~~
      compilation terminated.
      error: Cannot compile MPI programs. Check your configuration!!!
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mpi4py
Failed to build mpi4py
ERROR: Could not build wheels for mpi4py, which is required to install pyproject.toml-based projects

And ideas how can I properly load and run mpi4py ?


google search found this:

So I would try:

sudo dnf install openmpi-devel

Then pip install mpi4py

Thanks Tom.


Here is my solution and it seems to be working:

1) sudo dnf install python3-devel
2) sudo dnf install openmpi-devel
3) try:
    module avail
    if fails:
4) module load mpi/openmpi-x86_64 (what is says in module avail)
5) python3 -m pip install mpi4py

To run any program type

mpirun -np "# of cores" python ""

mpirun -np 2 python


I strongly recommend using virtualenv or python -m venv with pip as you can very easily end up conflicting with dnf installed libraries, which can in turn break system installed programs, and it is very much not fun to troubleshoot.


I have never encountered with a problem like that so far but I’ll try that from now on. Thanks for the heads-up.

It also seems that whenever I kill the terminal and open a new one, I should do module load mpi again, which seems odd…but it works.

The module is loaded in the terminal environment. When the terminal is closed everything it is running is also closed. Normal and should be expected.

1 Like

Maybe I can add some code to .bashrc so it load each time the terminal starts and then I delete the code when I am done with the project. It’s good to know that it’s expected behaviour.

That may work. Be careful though, because if you have multiple terminals open your code in .bashrc will run for each terminal when you open it.