Skip to content

Commit 4b6d545

Browse files
committed
enhance stdlib.has_python checks
Check for non-compatible Python vs. Matlab
1 parent 1566875 commit 4b6d545

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

+stdlib/private/pvt_python_version.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44

55
pe = pyenv();
66
vs = pe.Version;
7-
if stdlib.strempty(vs), return, end
7+
if stdlib.strempty(vs)
8+
return
9+
end
10+
11+
% check with Python basic type to check this Python version is compatible with Matlab.
12+
% for example, Python 3.13 isn't compatible with Matlab R2025a, and this should catch that.
13+
% by PythonError ImportError: PyCapsule_Import could not import module "libmwbuffer"'
14+
try
15+
py.tuple([1,1])
16+
catch
17+
return
18+
end
819

920
% this line may error like
1021
% "Python Error: TypeError: cannot create 'sys.version_info' instances"

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Normally the user does not specify the backend as we prioritize faster backends.
4646
* Linux / macOS: R2024b and newer
4747
* [Java](./Readme_java.md): all supported Matlab releases
4848
* [Perl](https://www.mathworks.com/help/matlab/ref/perl.html): Matlab R2018a and newer. This uses a system() call to Perl, which is bundled with Matlab on Windows and generally available on Linux and macOS
49-
* [Python](https://www.mathworks.com/help/matlab/call-python-libraries.html): Matlab R2022b and newer
49+
* [Python](https://www.mathworks.com/help/matlab/call-python-libraries.html): Matlab R2022b and newer. `stdlib.has_python` checks that the Python version set by `pyenv()` is compatible with the Matlab release.
5050
* System shell calls: all supported Matlab releases. As a backup when the platform doesn't have the primary (faster) methods available, the system shell can be called for some functions.
5151

5252
## Acknowledgments

0 commit comments

Comments
 (0)