Skandan C Y
Skandan C Y

Reputation: 1

Python ModuleNotFoundError: No module named 'Binding_py'

I am working on a Python project that uses a C++ extension module created with Pybind11. The C++ project is built with CMake on Jetbrains CLion, and the generated Python extension file is Binding.cp312-win_amd64.pyd.

I have a Python script (trial.py) that attempts to import the module as follows:

import sys
sys.path.append(r"D:\Binding\cmake-build-debug\Binds")
import Binding_py
print(Binding_py.add(2,3))
print(Binding_py.multiply(3,4)) 

My C++ project's name is Binding. The .pyd file is saves as Binding.cp312-win_amd64.pyd My python project's name is Binds, which resides inside cmake-build-debug of Binding. The .pyd file as well as my py file named as trial.py. are in the same directory 'Binds'.

PYBIND11_MODULE(Binding_py, m) {
    m.doc() = "Example module exposing C++ functions to Python"; 
    m.def("add", &add, "A function that adds two numbers");
    m.def("multiply", &multiply, "A function that multiplies two numbers");
}

When I try to run the above py code, I get the following error -

D:\Binding\cmake-build-debug\Binds\.venv\Scripts\python.exe D:\Binding\cmake-build-debug\Binds\trial.py 
Traceback (most recent call last):
  File "D:\Binding\cmake-build-debug\Binds\trial.py", line 26, in <module>
    import Binding_py
ModuleNotFoundError: No module named 'Binding_py'

I have verified that: The Binding.cp312-win_amd64.pyd file is located in the directory specified in sys.path.append(). I am using the 64-bit version of Python. I have tried rebuilding the project and checking for any missing dependencies, but the issue persists.

What steps can I take to resolve this ModuleNotFoundError and successfully import the Binding_py module?

Upvotes: 0

Views: 62

Answers (0)

Related Questions