Testing if a Python executable was detected, gracefully

Hello everybody,
I'm writing unit tests for code that calls some Python scripts. Early on, I would like to test whether MATLAB can find a valid Python executable. Naturally, the function to use in this case is `pyversion` - however, the documentation does not specify the expected outputs in case an executable is not found. I'm assuming these are empty strings/char arrays, but have no way of verifying that.
Another approach that would likely work is just trying to use the interface (with a fallback):
try
py.None; % or many other constants/functions that work when python is set up correctly
% ... it works
catch
% ... it doesn't work
end
However, this makes me cringe a little, since I'd rather avoid `try/catch` if there's an `if/else` that can achieve the same.
Can you please suggest a graceful non-windows-specific way to test if the current instance of MATLAB is able to interface with Python?

댓글 수: 3

Adam
Adam 2017년 8월 24일
편집: Adam 2017년 8월 24일
>> stuff = pyversion
stuff =
0×0 empty char array
This seems to work fine to test an ampty string.
Hi Adam - thank you for trying that! Which OS+MATLAB release did you get this on?
Windows 10 R2017a

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2017년 8월 24일

0 개 추천

Did you check "doc pyversion"?
The syntax is there:
[version, executable, isloaded] = pyversion

댓글 수: 1

Of course I checked it - it is also mentioned in the question.

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

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

질문:

2017년 8월 24일

댓글:

2017년 8월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by