[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: bindings that work from Python fail with "Cannot find class 'py.pybind11_builtins.pybind11_type'" when used from Matlab Python interface #3945

Open
3 tasks done
slayoo opened this issue May 16, 2022 · 7 comments
Labels
triage New bug, unverified

Comments

@slayoo
Copy link
slayoo commented May 16, 2022

Required prerequisites

Problem description

Basic things like instantiation of a pybin11-exposed C++ class, that do work when called from Python, stop to work when called from the Matlab Python interface (through the same install pybind11-generated Python package). There is just a "Cannot find class 'py.pybind11_builtins.pybind11_type" error shown. Any clues on how to debug it or what is causing the error? Thanks!

Reproducible example code

Minimal reproducer with succeeding code/GH action in Python and failing GH action for Matlab here: https://github.com/slayoo/pybind_matlab_issue

OK Python: https://github.com/slayoo/pybind_matlab_issue/actions/runs/6911677790/job/18806501098
KO Matlab: https://github.com/slayoo/pybind_matlab_issue/actions/runs/6911677788/job/18806501100

@slayoo slayoo added the triage New bug, unverified label May 16, 2022
@slayoo
Copy link
Author
slayoo commented May 19, 2022

Fort the record, noting down here the reply from Gitter by @Holt59:

You should report this on the Matlab side because it's most likely not a pybind11 issue. That py. prefix in the class not found is probably the issue, but it's probably added by Matlab or somewhere else because it should not be there.

@acampbel could you help us here? The issue is that while using a C++-implemented package that works OK from Python, when loading it from Matlab, there is some problem loading share libraries as the symbols seem to have an additional "py." prefix that prevents them from being correctly located. The error message is: "Cannot find class 'py.pybind11_builtins.pybind11_type'." (while the class name is just pybind11_builtins.pybind11_type, without the py.). I've prepared a minimal reproducer using the Matlab actions (see links above). Thanks!

@slayoo
Copy link
Author
slayoo commented May 20, 2022

For the record, noting here down a comment from Gitter by @jeandet

could they have done something like this https://stackoverflow.com/questions/6940384/how-to-deal-with-symbol-collisions-between-statically-linked-libraries/6940389#6940389?
did you try to do some nm or readelf on their elf files?

@slayoo
Copy link
Author
slayoo commented Nov 4, 2023

@slayoo
Copy link
Author
slayoo commented Nov 18, 2023

@henryiii, @rwgk, let me take the liberty of "pinging" if you'd have any hints on how to workaround this issue, i.e. make pybind11-based packages usable under the Matlab Python interface?

The issue is (with a minimalistic CI reproducer here: https://github.com/slayoo/pybind_matlab_issue - see also links above to logs of CI runs depicting the problem) that a correctly functioning pybind11-based Python module, when imported in Matlab throws:

  Cannot find class 'py.pybind11_builtins.pybind11_type'.

Implying that Matlab seems to prefix the symbols with the bogus "py.".
Thanks!

@rwgk
Copy link
Collaborator
rwgk commented Nov 18, 2023

if you'd have any hints on how to workaround this issue

I briefly looked, but sorry, I don't have any hints.

The logs will expire, I recommend you paste the critical messages here. It'll also make it more likely that others with the same problem find this bug (and then maybe you can stick your heads together to solve it).

It's not certain (at all) that the problem is rooted in pybind11. If you reduce the problem to a pybind11 PR that fails in the pybind11 GHA I'll take another look.

/home/runner/work/_actions/matlab-actions/run-command/v0/dist/bin/run_matlab_command.sh cd('/tmp/run_matlab_command-E64Swj'); command_a13eb2e9_a96f_46a8_92e6_7cd68565fbda
  
  	Sponsored License -- for use in support of a program or activity sponsored by MathWorks.
  	Not for government, commercial or other non-sponsored organizational use.
  
  
  ver =
  
      '0.1.dev1+gf22d8c9'
  
  	linux-vdso.so.1 (0x00007ffd51ddc000)
  	libstdc++.so.6 => /usr/local/MATLAB/R2022a/sys/os/glnxa64/libstdc++.so.6 (0x00007fe4cc3c2000)
  	libgcc_s.so.1 => /usr/local/MATLAB/R2022a/sys/os/glnxa64/libgcc_s.so.1 (0x00007fe4cc3a8000)
  	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe4cc1a6000)
  	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe4cc057000)
  	/lib64/ld-linux-x86-64.so.2 (0x00007fe4cc5ba000)
  
  ans =
  
       0
  
  {�Error using readme
  Cannot find class 'py.pybind11_builtins.pybind11_type'.
  
  Error in command_a[13](https://github.com/slayoo/pybind_matlab_issue/actions/runs/6911677788/job/18806501100#step:7:15)eb2e9_a96f_46a8_92e6_7cd68565fbda (line 1)
  cd('/home/runner/work/pybind_matlab_issue/pybind_matlab_issue'); readme
  }�

@slayoo
Copy link
Author
slayoo commented Nov 19, 2023

Thank you, @rwgk!

If you reduce the problem to a pybind11 PR that fails in the pybind11 GHA I'll take another look.

voilà: pybind/cmake_example#164

@slayoo
Copy link
Author
slayoo commented Nov 25, 2023

For the record, a workaround for this problem was proposed by @rwgk at pybind/cmake_example#164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

No branches or pull requests

2 participants