Testing if a Python executable was detected, gracefully

2 views (last 30 days)
Dev-iL on 24 Aug 2017
Commented: Dev-iL on 24 Aug 2017
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):
py.None; % or many other constants/functions that work when python is set up correctly
% ... it works
% ... it doesn't work
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?

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 24 Aug 2017
Did you check "doc pyversion"?
The syntax is there:
[version, executable, isloaded] = pyversion
  1 Comment
Dev-iL on 24 Aug 2017
Of course I checked it - it is also mentioned in the question.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by