解决: _configtest.c:2:10: fatal error: mpi.h: No such file or directory #include <mpi.h>

在pip install mpi4py时遇到了以下问题

Collecting mpi4py
  Using cached https://files.pythonhosted.org/packages/ec/8f/bbd8de5ba566dd77e408d8136e2bab7fdf2b97ce06cab830ba8b50a2f588/mpi4py-3.0.3.tar.gz
Building wheels for collected packages: mpi4py
  Running setup.py bdist_wheel for mpi4py ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-Nx6jsq/mpi4py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmp4LHvmYpip-wheel- --python-tag cp27:

(中间一大段略)
    checking for MPI compile and link ...
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-5Z483E/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c _configtest.c -o _configtest.o
    _configtest.c:2:10: fatal error: mpi.h: No such file or directory
     #include 
              ^~~~~~~
    compilation terminated.
    failure.
    removing: _configtest.c _configtest.o
    error: Cannot compile MPI programs. Check your configuration!!!
    
    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-Nx6jsq/mpi4py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-I1xksM-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-Nx6jsq/mpi4py/

解决方法:

sudo apt install libopenmpi-dev
pip install mpi4py
Collecting mpi4py
  Using cached https://files.pythonhosted.org/packages/ec/8f/bbd8de5ba566dd77e408d8136e2bab7fdf2b97ce06cab830ba8b50a2f588/mpi4py-3.0.3.tar.gz
Building wheels for collected packages: mpi4py
  Running setup.py bdist_wheel for mpi4py ... done
  Stored in directory: /root/.cache/pip/wheels/18/e0/86/2b713dd512199096012ceca61429e12b960888de59818871d6
Successfully built mpi4py
Installing collected packages: mpi4py
Successfully installed mpi4py-3.0.3

参考:
https://www.e-learn.cn/topic/2981810

你可能感兴趣的:(python,linux)