フィルターのクリア

Python dependency via direct calls to py in class method?

1 回表示 (過去 30 日間)
Steven Giannacopoulos
Steven Giannacopoulos 2022 年 11 月 7 日
編集済み: Steven Giannacopoulos 2022 年 11 月 8 日
Hello,
When trying instantiate a class, I'm getting an error related to CPython:
Error using SomeDummyClass
Python commands require a supported version of CPython. See Getting Started with Python.
None of the object's properties are Python objects. What's the deal? My class has an unrelated function that calls python directly using py. Could that be the issue? I currently don't have python installed on the workstation in question. I don't need it - I don't need the function that calls python for what I am working on.
Thanks!
P.S. I really hope a guy named Martin Caron can answer this question...

採用された回答

Martin Caron
Martin Caron 2022 年 11 月 7 日
Hi --Person who I've never met-- Steven,
I happen to have a few insights on the matter. Doing a quick example class (see below), the following observations were made when instanciating this class. Note that we'll only cover the instanciation case, not the calling of those functions, as it is pretty easy to see that they will crash.
classdef SomeDummyClass
properties
Foo (1,1)double
end
methods
function SomethingThatClearlyUsesPython(this)
% This crashes when python is not installed
py.SomePackage.SomeFunction();
end
function SomethingThatIndirectlyUsesPython(this)
% This does not crash
ThisFunctionCallsPyDotSomePackageDotSomeFunction();
end
function out = SomethingThatUsesANonexistantClass(this, other)
arguments
this
other (1,1)ThisClassDoesNotExist
end
% This does not crash
out = ThisClassDoesNotExist();
end
end
end
When python is not installed, only direct calls to "py." cause the error on instanciation. If we comment out the whole "SomethingThatClearlyUsesPython" function, the instanciation works without any issue.
From this, I would hypothesize that:
Matlab does not care about the contents of class methods during instanciation, except if there is "py." somewhere inside it.
Would be nice if a Matlab person could confirm if this statement is truly accurate, but so far it seems to be empyrically correct.
I would recommend moving the direct calls to "py." outside of your class, this will allow you to load the data without caring about what is contained inside the functions.
Cheers!
  1 件のコメント
Steven Giannacopoulos
Steven Giannacopoulos 2022 年 11 月 8 日
Wow! Thanks for your help! Your answer is so good, I feel like I participated in the process. I owe you a coffee at the machine in the Connect Zone. Cheers!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by