필터 지우기
필터 지우기

Python dependency via direct calls to py in class method?

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Call 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