Error loading MPI DLL in mpi4py

后端 未结 6 1817
面向向阳花
面向向阳花 2020-12-16 02:00

I am trying to use Mpi4py 1.3 with python 2.7 on Windows 7 64bits. I downloaded the installable version from here which includes OpenMPI 1.6.3 so in the installed directory

6条回答
  •  难免孤独
    2020-12-16 03:01

    Use sys.prefix\lib\site-packages\mpi4py\bin\python-mpi.exe or add the following code to sys.prefix\lib\site-packages\mpi4py\__init__.py around line 37:

    def _init_openmpi():
        """Pre-load libmpi.dll and register OpenMPI distribution."""
        import os
        import ctypes
        if os.name != 'nt' or 'OPENMPI_HOME' in os.environ:
            return
        try:
            openmpi_home = os.path.abspath(os.path.dirname(__file__))
            openmpi_bin = os.path.join(openmpi_home, 'bin')
            os.environ['OPENMPI_HOME'] = openmpi_home
            os.environ['PATH'] = ';'.join((openmpi_bin, os.environ['PATH']))
            ctypes.cdll.LoadLibrary(os.path.join(openmpi_bin, 'libmpi.dll'))
        except Exception:
            pass
    
    _init_openmpi()
    

提交回复
热议问题