matlab_kernel
matlab_kernel copied to clipboard
unintelligible codes
When the matlab code is wrong, the tips can't show correctly. My pc's default language is Chinese. I don't know if that's the reason.
wrong one:
x=1:1:100; y=10*x*x; plot(x,y) title('test')
correct one:
x=1:1:100; y=10*x.*x; plot(x,y) title('test')
tip:
Hi, this seems to be something to do with encoding. Which Python version are you using? I recall that "MATLAB engine for Python" supports python 2.7, which might cause problems when encountering Unicode Characters (like Chinese characters), but there should be no problems with Python 3.x versions.
Hi, this seems to be something to do with encoding. Which Python version are you using? I recall that "MATLAB engine for Python" supports python 2.7, which might cause problems when encountering Unicode Characters (like Chinese characters), but there should be no problems with Python 3.x versions.
It seemed to be python 3.8 and MATLAB 2020b. I just tried it again and the error could display correctly this time with python 3.8 and MATLAB 2021b. Thanks for your help anyway!
I encountered a similar problem: fprintf('→\n')
produces an entirely different symbol in the output.
That symbol is "Non-printable U+001A".
Here is the produced cell:
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001a\n"
]
}
],
"source": [
"fprintf('→\\n')"
]
},
My system:
Debian GNU/Linux 11.6, kernel 5.10.0-21-amd64
Locale LANG=en_US.UTF-8
.
MATLAB 9.13.0.2166757 (R2022b) Update 4
Python 3.10
The problem seems to be related to MatlabKernel._execute_async
. An extremely hacky workaround is to comment out the import of pipes
from wurlitzer
in kernel.py
:
# try:
# from wurlitzer import pipes
# except Exception:
# pipes = None
pipes = None
Dug a little deeper: The problem is caused by a bug in the Matlab engine for Python:
https://github.com/mathworks/matlab-engine-for-python/issues/34
Thanks @allefeld for the info!