20

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 (*/Python27\Lib\site-packages\mpi4py\lib) following libraries exist: libmpi.lib, libmpi_cxx.lib, libopen-pal.lib, and libopen-rte.lib. Now in my codes when trying to import it:

from mpi4py import MPI

It returns following error:

ImportError: DLL load failed: The specified module could not be found.

I tried to copy a bove lib files alongside the */Python27\Lib\site-packages\mpi4py\MPI.pyd and even to Windows/System32, but it didn't work. I appreciate your help on what DLL is missing and how to fix the error?

nbro
  • 15,395
  • 32
  • 113
  • 196
Aso Agile
  • 417
  • 1
  • 6
  • 13
  • *.lib are either static library archives or import libraries. These are definitely _not_ DLLs. – Hristo Iliev Dec 23 '12 at 09:16
  • Thanks @HristoIliev for your comment.You right *.lib are static library which in this case OpenMPI is provided in form of. Then what DLL is missing? – Aso Agile Dec 23 '12 at 12:40
  • Sorry, never used mpi4py, lest on Windows. Check the installation directory. May be there is a bitness mismatch (there were some Windows installation problems discussed recently on the Open MPI mailing lists...) – Hristo Iliev Dec 23 '12 at 20:50

8 Answers8

17

Using Mpi4py 1.3 with python 3.5 on Windows 10, I can run import mpi4py successfully but not from mpi4py import MPI. To fix it, just reinstall MPI via MPI. This works for me.

R_Z
  • 189
  • 1
  • 4
11

I solved the problem. My environment is Win10, python 3.6.6, pycharm 2019.2 and linked to annaconda visual env.
1. download MS MPI, install both .mis and SDK.
2. set up environmental variables
control panel --> advanced system settings --> environmental variables --> add
(1) C:\Program Files (x86)\Microsoft SDKs\MPI and
(2) C:\Program Files\Microsoft MPI\Bin. There are my paht, you may need to change the path here.
3. install MS visual studio, community version is enough
4. Anaconda prompt, use conda install -c intel mpi4py. I read most replies but not mentioned this way.

ERIC
  • 460
  • 6
  • 16
5

I had the same issue and no answer solved the issue.

For me, the following solved the problem. I compiled and installed the mpi4py manually as follows:

  • Install MPI SDK 10 for Windows from https://duongtrungnghia.wordpress.com/2017/03/28/install-mpi4py-on-windows-10/
  • Add C:\Program Files (x86)\Microsoft SDKs\MPI\Lib and C:\Program Files (x86)\Microsoft SDKs\MPI to your Windows environment variables (not sure if needed)
  • You need Visual Studio Build Tools with MSVC 140 or pure Visual Studio. Not sure what version. In my case, the mpi4py setup.py used C:\Program Files (x86)\Microsoft Visual Studio 14.0\.... although I use VS2017 currently.
  • Install Windows SDK/Kits and dev tools (https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk)
    • Open Developer Command Prompt (It is like a CMD with some extras)
    • Activate your venv by executing (venv/Scripts/activate) if you use Virtualenv
    • Create and change to a temp directory and do the following:
      • git clone https://github.com/mpi4py/mpi4py.git
      • cd mpi4py
      • python -m pip install Cython
      • python setup.py build
      • python setup.py install

My setting:

  • Windows 10
  • Python 3.7
User128525
  • 51
  • 1
  • 4
  • Updated link to download MPI binaries and MPI SDK, both have to be installed in as a prerequisite: https://www.microsoft.com/en-us/download/details.aspx?id=100305 – Sheece Gardazi Sep 25 '19 at 03:53
3

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()
cgohlke
  • 9,142
  • 2
  • 33
  • 36
  • I tried this, I added the code both before before and after the `def get_include():` function, but it doesn't work. I don't quite get the first solution you propose. – Toke Faurby Jul 10 '18 at 11:45
  • This answer is long obsolete. It applies to a 5 year old binary of mpi4py that was linked to OpenMPI. – cgohlke Jul 11 '18 at 06:47
  • Makes sense, but do you have an idea as to how to fix it now? – Toke Faurby Jul 11 '18 at 10:15
  • I don't have windows to try, but maybe trying 'conda install mpi4py' might solve your problem. Similar workaround for linux: https://stackoverflow.com/a/38332136/1716869 – GrigorisG Jan 04 '19 at 11:08
2

I tried the following and it worked.

  1. Uninstalling OpenMPI
  2. Uninstalling mpi4py
  3. Installing Microsoft MPI
  4. Re-installing mpi4py with pip so that a wheel gets installed

Source: https://groups.google.com/d/msg/mpi4py/VA7Aihi64R0/jnxAT2HtCgAJ

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
DailyReader
  • 43
  • 1
  • 8
2

I fixed the error by installing the latest version of MSMPI from https://github.com/Microsoft/Microsoft-MPI

1

For anyone who gets this error "from mpi4py import MPI ImportError: DLL load failed: The specified procedure could not be found." i solved it by downgrade the MSMPI to V10.0 it did not work with V10.2. And use MPISdk V8.0 you have to uninstall the MSMPI that you have it now and install V10.0 from this link MSMPIV10.0 It does not accept to install new version without uninstalling the old one, hopefully it's gonna work

Zaher
  • 11
  • 4
0

In my case, Microsoft MPI was not installed. Make sure you have it.

https://www.microsoft.com/en-us/download/details.aspx?id=57467