Matlab fails to run Python built with Pybind

조회 수: 33 (최근 30일)
Jay Castro
Jay Castro 2023년 10월 9일
댓글: David Truscott 2023년 12월 11일
Attempting to call a member of a user-defined Python module which was built using Pybind. The module seems to import correctly via
mymodule = py.importlib.import_module("mymodule")
But on attempting to access a class from the module, I get this error:
>> myclass = mymodule.myclass
Cannot find class 'py.pybind11_builtins.pybind11_type'.
I've tested that the module loads and works correctly when accessed in Python. I'm using Matlab on Ubuntu, and Python 3.10
  댓글 수: 6
Sylwester Arabas
Sylwester Arabas 2023년 11월 22일
Update: a workaround has just been proposed and succesfully tested here: https://github.com/pybind/cmake_example/pull/164
David Truscott
David Truscott 2023년 12월 11일
This is the work-around for that error that worked for me on Windows:
Create a file called 'pybind11_builtins.py' and place it in the folder where your python modules library resides. (For my Python 3.10 installation in Windows, it was {Path to Python Installation} \Lib folder.
The only line in that file should be 'pybind11_type=type' (without the apostrophes).
Reload your pyenv in Matlab,
>>py.importlib.import_module('pybind11_builtins')
>>py.importlib.import_module(' Your originally intended module here')

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by