question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing the C API fails on Windows

See original GitHub issue

I am trying to build a C++ Python extension (with pybind11) that uses MPI and mpi4py on Windows. I am working in a conda environment and I installed mpi4py as follows:

conda install mpi4py -c conda-forge --yes

The following:

// import the mpi4py API
if (import_mpi4py() < 0) {
  throw std::runtime_error("Could not load mpi4py API.");
}

throws the exception with traceback:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\IEUser\VeloxChemMP\build_dbg_14.27\lib\python3.8\site-packages\veloxchem\__init__.py", line 2, in <module>
    from .veloxchemlib import AtomBasis
ImportError: Could not load mpi4py API.

Running mpiexec -n 4 python -c “from mpi4py import MPI; comm = MPI.COMM_WORLD; print(comm.Get_rank())” works as expected. I am not sure whether this is a bug or some silly mistake I am making.

This issue was migrated from moved from BitBucket #177

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:60 (38 by maintainers)

github_iconTop GitHub Comments

2reactions
dalcinlcommented, Apr 30, 2021

I’ll merge the bugfix/msmpi branch soon.

1reaction
robertodrcommented, May 3, 2021

@robertodr Thanks! About a new mpi4py release, it will happen eventually, but not immediately. However, we could easily patch the current conda-forge package to include this fix. Would that be convenient to you?

Remember that if you pass -DPyMPI_HAVE_MPI_Message to your compiler flags, the current release mpi4py release still works.

Or you can keep using the following in your code:

#include <mpi.h>

#ifdef MSMPI_VER
#define PyMPI_HAVE_MPI_Message 1
#endif

#include <mpi4py/mpi4py.h>

I will keep using the #ifdef ... #define ... in my code, keeping an eye out for new releases. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

mpi4py / mpi4py / issues / #177 - Importing the C API fails on Windows
I am trying to build a C++ Python extension (with pybind11) that uses MPI and mpi4py on Windows. I am working in a...
Read more >
Python gives error when importing simple C extension module
When I rename hello. dll to hello. pyd I get a different error ">>> import hello Traceback (most recent call last): File "<stdin>",...
Read more >
Import error (on Windows): dependency? · Issue #1084 - GitHub
The code import amici fails even though installation via pip install amici works without error (which was also checked using verbose mode).
Read more >
Changelog — Python 3.11.1 documentation
bpo-40280: subprocess now imports Windows-specific imports when msvcrt module is available, and POSIX-specific imports on all other ...
Read more >
LoadLibraryA function (libloaderapi.h) - Win32 apps
If the function cannot find the module, the function fails. When specifying a path, be sure to use backslashes (\), not forward slashes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found