Import custom module not working (.pyd-file) I have a file called cmake_example.cp37-win_amd64.pyd, which I've built using pybind11 (code below). It is located in Python\Python37\Lib\site-packages.

I also have a file called test.py which is simply doing the following:

import cmake_example as m
print(m.add(39,3))
&gt;&gt;&gt; 42


Everything is working just fine when I run this with the python install I have on my system.

I want to use this .pyd-file in blender, but I can't get it to import the module.

import cmake_example as m


gives the following error:

File "\test.py", line 1, in &lt;module&gt;
ImportError: No module named 'cmake_example'
Error: Python script fail, look in the console for now...


I've tried to place the .pyd-file according to the result I get from running

import sys
print(sys.path)


inside blender.

I'm experienced when it comes to both C++ and Blender, but not Python. However, the .pyd-file is doing everything I want outside of Blender, but not inside. Any suggestions on how to successfully import the module?



C++ code:

#include &lt;pybind11/pybind11.h&gt;

int add(int a, int b) {
    return a + b;
}

namespace py = pybind11;

PYBIND11_MODULE(cmake_example, m) {
    m.doc() = R"pbdoc(
        Pybind11 example plugin
        -----------------------

        .. currentmodule:: cmake_example

        .. autosummary::
           :toctree: _generate

           add
    )pbdoc";

    m.def("add", &amp;add, R"pbdoc(
        Add two numbers

        Some other explanation about the add function.
    )pbdoc");

#ifdef VERSION_INFO
    m.attr("__version__") = VERSION_INFO;
#else
    m.attr("__version__") = "dev";
#endif
}
You need to have the exact same version of Python as used in Blender, and have it (and your module) built with the same compiler. After that, make sure that the module is on sys.path.