OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

pybind11 cannot import simplest module

  • Thread starter Thread starter roi_saumon
  • Start date Start date
R

roi_saumon

Guest
I just started with pybind11 and I wanted to try the minimal example they provide on their page.

Code:
#include <pybind11/pybind11.h>

int add(int i, int j) {
    return i + j;
}

PYBIND11_MODULE(example, m) {
    m.doc() = "pybind11 example plugin"; // optional module docstring

    m.def("add", &add, "A function that adds two numbers");
}

I am using visual studio 2022 and I can compile the solution without problem as a dll. This gives me inside the directory x64/Debug the following files

Code:
example.dll
example.exp
example.lib
example.pdb

I then go inside the x64/Debug folder and and run python 3.12 (the same version as I used in pybind11), but when I do

Code:
>>> import example

I get the following

Code:
>>> import example
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'example'

What am I doing wrong?
<p>I just started with pybind11 and I wanted to try the <a href="https://pybind11.readthedocs.io/en/stable/basics.html#creating-bindings-for-a-simple-function" rel="nofollow noreferrer">minimal example</a> they provide on their page.</p>
<pre><code>#include <pybind11/pybind11.h>

int add(int i, int j) {
return i + j;
}

PYBIND11_MODULE(example, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring

m.def("add", &add, "A function that adds two numbers");
}
</code></pre>
<p>I am using visual studio 2022 and I can compile the solution without problem as a dll. This gives me inside the directory <code>x64/Debug</code> the following files</p>
<pre><code>example.dll
example.exp
example.lib
example.pdb
</code></pre>
<p>I then go inside the <code>x64/Debug</code> folder and and run python 3.12 (the same version as I used in pybind11), but when I do</p>
<pre><code>>>> import example
</code></pre>
<p>I get the following</p>
<pre><code>>>> import example
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'example'
</code></pre>
<p>What am I doing wrong?</p>
 

Latest posts

D
Replies
0
Views
1
Dhanushka Amarakoon
D
S
Replies
0
Views
1
Shikhar Ambashta
S
Top