Error loading MPI DLL in mpi4py












4















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 (*/Python27Libsite-packagesmpi4pylib) 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 */Python27Libsite-packagesmpi4pyMPI.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?



Thanks,



@Aso.agile










share|improve this question

























  • *.lib are either static library archives or import libraries. These are definitely not DLLs.

    – Hristo Iliev
    Dec 23 '12 at 9: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
















4















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 (*/Python27Libsite-packagesmpi4pylib) 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 */Python27Libsite-packagesmpi4pyMPI.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?



Thanks,



@Aso.agile










share|improve this question

























  • *.lib are either static library archives or import libraries. These are definitely not DLLs.

    – Hristo Iliev
    Dec 23 '12 at 9: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














4












4








4


1






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 (*/Python27Libsite-packagesmpi4pylib) 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 */Python27Libsite-packagesmpi4pyMPI.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?



Thanks,



@Aso.agile










share|improve this question
















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 (*/Python27Libsite-packagesmpi4pylib) 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 */Python27Libsite-packagesmpi4pyMPI.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?



Thanks,



@Aso.agile







python python-2.7 openmpi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 23 '12 at 12:37







Aso Agile

















asked Dec 22 '12 at 16:23









Aso AgileAso Agile

142412




142412













  • *.lib are either static library archives or import libraries. These are definitely not DLLs.

    – Hristo Iliev
    Dec 23 '12 at 9: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



















  • *.lib are either static library archives or import libraries. These are definitely not DLLs.

    – Hristo Iliev
    Dec 23 '12 at 9: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

















*.lib are either static library archives or import libraries. These are definitely not DLLs.

– Hristo Iliev
Dec 23 '12 at 9:16





*.lib are either static library archives or import libraries. These are definitely not DLLs.

– Hristo Iliev
Dec 23 '12 at 9: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







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





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












2 Answers
2






active

oldest

votes


















2














Use sys.prefixlibsite-packagesmpi4pybinpython-mpi.exe or add the following code to sys.prefixlibsite-packagesmpi4py__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()





share|improve this answer


























  • 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 6: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: stackoverflow.com/a/38332136/1716869

    – GrigorisG
    Jan 4 at 11:08



















1














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.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14004457%2ferror-loading-mpi-dll-in-mpi4py%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Use sys.prefixlibsite-packagesmpi4pybinpython-mpi.exe or add the following code to sys.prefixlibsite-packagesmpi4py__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()





    share|improve this answer


























    • 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 6: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: stackoverflow.com/a/38332136/1716869

      – GrigorisG
      Jan 4 at 11:08
















    2














    Use sys.prefixlibsite-packagesmpi4pybinpython-mpi.exe or add the following code to sys.prefixlibsite-packagesmpi4py__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()





    share|improve this answer


























    • 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 6: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: stackoverflow.com/a/38332136/1716869

      – GrigorisG
      Jan 4 at 11:08














    2












    2








    2







    Use sys.prefixlibsite-packagesmpi4pybinpython-mpi.exe or add the following code to sys.prefixlibsite-packagesmpi4py__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()





    share|improve this answer















    Use sys.prefixlibsite-packagesmpi4pybinpython-mpi.exe or add the following code to sys.prefixlibsite-packagesmpi4py__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()






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 8 '13 at 15:47

























    answered Jan 8 '13 at 15:23









    cgohlkecgohlke

    7,75912425




    7,75912425













    • 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 6: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: stackoverflow.com/a/38332136/1716869

      – GrigorisG
      Jan 4 at 11:08



















    • 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 6: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: stackoverflow.com/a/38332136/1716869

      – GrigorisG
      Jan 4 at 11:08

















    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







    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 6:47





    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 6:47













    Makes sense, but do you have an idea as to how to fix it now?

    – Toke Faurby
    Jul 11 '18 at 10:15





    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: stackoverflow.com/a/38332136/1716869

    – GrigorisG
    Jan 4 at 11:08





    I don't have windows to try, but maybe trying 'conda install mpi4py' might solve your problem. Similar workaround for linux: stackoverflow.com/a/38332136/1716869

    – GrigorisG
    Jan 4 at 11:08













    1














    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.






    share|improve this answer




























      1














      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.






      share|improve this answer


























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 27 at 14:33









        R_ZR_Z

        111




        111






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14004457%2ferror-loading-mpi-dll-in-mpi4py%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents