Python 3.8 Compatibility Issue w/ 2023a
31 views (last 30 days)
Show older comments
I'm having an issue that seems to do with compatibility of python 3.8 with 2023a.
Currently when I try to convert a 2-D array into a python function I am met with the ofllowing error:
Python Error: ModuleNotFoundError: No module named 'libmwbuffer'
Python function '' might not be able to accept at least one input argument at position 1. The function
may require a specific data type that you can construct from the MATLAB array. For more information, see
the documentation for Python function '' and working with Python arrays.
I have found a similar issue catalogued in this question from 2021: https://www.mathworks.com/matlabcentral/answers/856060-matlab-not-converting-2d-arrays-to-python-arrays-no-module-named-libmwbuffer-error?s_tid=srchtitle in which this person was having the exact same problem.
The following link was provided in an answer which highlights compatibility, and clearly shows that now (2023) the 2023a distribution of Matlab should support python 3.8: https://www.mathworks.com/support/requirements/python-compatibility.html
For clarity, the rest of the python functionality I am looking for is working; I can even pass a 1xN array in matlab to python and get an array
Example 1 (1xN):
input: np = py.importlib.import_module('numpy');
np.array(ones(1, 5))
output:
ans =
Python ndarray with properties:
T: [1×1 py.numpy.ndarray]
base: [1×1 py.NoneType]
ctypes: [1×1 py.numpy.core._internal._ctypes]
data: [1×5 py.memoryview]
dtype: [1×1 py.numpy.dtype[float64]]
flags: [1×1 py.numpy.core.multiarray.flagsobj]
flat: [1×1 py.numpy.flatiter]
imag: [1×1 py.numpy.ndarray]
itemsize: [1×1 py.int]
nbytes: [1×1 py.int]
ndim: [1×1 py.int]
real: [1×1 py.numpy.ndarray]
shape: [1×1 py.tuple]
size: [1×1 py.int]
strides: [1×1 py.tuple]
[1. 1. 1. 1. 1.]
Example 2 (M x N):
input: np = py.importlib.import_module('numpy');
np.array(ones(2, 5))
output: Python Error: ModuleNotFoundError: No module named 'libmwbuffer'
Python function '' might not be able to accept at least one input argument at position 1. The function
may require a specific data type that you can construct from the MATLAB array. For more information, see
the documentation for Python function '' and working with Python arrays.
*Note: I have also tried directly using py.numpy.array(ones(2, 5)), this also gives me the same results above
3 Comments
Jeremy Ward
on 18 Apr 2024
@Nick Donatelli Hey thanks for the information! Without the ability to pass arrays this interface is not super useful. I hope they fix it soon.
Answers (2)
Giacomo Viganò
on 26 Jun 2024
Edited: Giacomo Viganò
on 26 Jun 2024
Had the same exactly issue. Restarting matlab solved it. I don't know why.
0 Comments
Karanjot
on 4 Jan 2024
Hi Nick,
I understand that you are encountering the following while using python functions within MATLAB:
Python Error: ModuleNotFoundError: No module named 'libmwbuffer'
Python function '' might not be able to accept at least one input argument at position 1. The function
may require a specific data type that you can construct from the MATLAB array. For more information, see
the documentation for Python function '' and working with Python arrays.
I recommend using the 'pyenv' function in MATLAB to check which Python environment is being used. Ensure that it's the correct one where 'numpy' is installed. If it's not the correct environment or if you want to change it, you can set it using:
pyenv(Version="executable")
where executable is the full path to the Python executable file.
Aditionally, If numpy is not installed in the Python environment that MATLAB is using, you will need to install it. You can do this outside of MATLAB by activating the Python environment and using pip:
pip install numpy
If you still experience the error after trying these troubleshooting steps, I recommend contacting MathWorks Technical Support: http://www.mathworks.com/support/contact_us/index.html
I hope this helps!
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!