50

I'm trying to install mpi4py using pip install mpi4py, but I'm getting the following error:

error: Cannot find 'mpi.h' header. Check your configuration!!!

Earlier in the same error report I have,

clang: error: linker command failed with exit code 1 (use -v to see    invocation)

What might the problem be?

Thanks!

2
  • 3
    What commands do you execute? Do you have MPI installed? Commented Feb 10, 2015 at 22:21
  • what is os x-specific about this? Commented Apr 23, 2015 at 15:11

10 Answers 10

61

As the error says, there are libraries missing. I solved it by installing libopenmpi-dev package

sudo apt-get install libopenmpi-dev

and then installed the mpi4py using pip

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

3 Comments

Note that this question was tagged osx and apt implies debian/ubuntu/related variants (but not saying this answer is bad)
Please don't do sudo pip install XXX
I am in a machine without sudo permissions. Yet I have conda. In that case, @9Dragons' answer solves it. conda install -c conda-forge mpi4py mpich
42

I met with the similar problem and fixed this by firstly

brew install mpich

And then

pip install mpi4py

Comments

13

you can do this:

brew install mpich

then

sudo find / -name mpicc

finally

env MPICC=/yourpath/mpicc pip3 install mpi4py

1 Comment

The second step was not necessary in my case.
12

None of the above solutions worked for me. I just use the conda install:

brew install mpich
conda install mpi4py

Comments

6

If mpi4py cannot find mpi.h, then likely the problem is how you are pointing mpi4py to your existing mpi library.

$ python setup.py build --mpicc=/where/you/have/mpicc

Now, there there are a few special cases related to OS X. You should consult http://mpi4py.scipy.org/docs/usrman/install.html to see if any apply to you.

1 Comment

if you want to use pip, you can do: env MPICC=/path/to/mpicc/ pip install mpi4py
6

in my case, all solutions above is failed but succeded by conda

conda install -c conda-forge mpi4py mpich

Comments

2

If somebody stumbles by and has the same problem I had:

I wanted to install mpi4py using pip as root:

sudo pip install mpi4py

I got the error message that mpi.h was missing during the installation. The path was set correctly, but only for my user, not for root. So if you run into trouble with missing libraries/headers during any installation, make sure the correct environment is also set up for root.

As I use mpi-selector to select which mpi implementation you use, I just had to run mpi-selector as root to set up everything correctly, and the installation succeeded.

1 Comment

mpi.h is a header file and LD_LIBRARY_PATH is for libraries. The issue was more likely with your $PATH (e.g. mpicc and friends were not in your default path)
1

I have the similar issue, the following helps me as well.

sudo apt install libopenmpi-dev

Comments

0

This might help on Fedora 38:

sudo dnf install python3-mpi4py-mpich python3-mpi4py-openmpi # second one not necessary I guess
module load mpi/mpich-$(arch)
pip3 install mpi4py

Mentioned here = https://mpi4py.readthedocs.io/en/latest/install.html2

Comments

-4

first post here and new to python , sorry if im off topic.

i finally installed mpi4py

1) by downloading the right version from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#mpi4py

2) open cmd ,change directory to where the downloaded file is

3) pip install some-package.whl ( How do I install a Python package with a .whl file? )

2 Comments

Hi @Frikg, welcome to Stack Overflow. Indeed, your answer doesn't seem to be addressing the specific problem that the original poster had, and seems offtopic!
hi @frandroid , you are right . I 've been searching for days to install it so i hope that someone who has the same issue with me will come across with my answer (title helps to easy find this post) :)

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.