1. Install Xcode
Launch commands in terminal:
$ xcode-select --install
$ ln -s ~/.bash_frofile ~/.bashrc
2. Download the source code form https://www.open-mpi.org/software/ompi/v2.1/ Usually you may choose openmpi-2.1.0.tar.gz
Launch commands in terminal:
$ tar zxvf openmpi-2.1.0.tar.gz
$ ./configure --prefix=/usr/local
$ make all
$ sudo make install
Then finally use $ pip install MPI4py