Trouble importing Python Modules in MATLAB
3 views (last 30 days)
Show older comments
While I can run simple scripts, I cannot run scripts that import modules such as numpy or pathlib. While I realize this question has been asked many times before, I can't seem to find any of the files or succesfully change the MATLAB search path.
When running a scipt the error I get is:
ModuleNotFoundError: No module named 'numpy'
When attempting to use py.anything I get:
Unable to resolve the name py.importlib.import_module.
When I type pyversion nothing happens
I have Anaconda3 downloaded as well as CPython 64-bit. MATLAB version 2019b for reference.
I understand I have to fix the search path but when I add the path (or attempt to) nothing happens and I continue to get the same errors. Also I realize most of these issues are addressed in the documentation, but as someone not familiar with this software it is a little too tricky for me to figure out.
1 Comment
Answers (1)
Harsha Priya Daggubati
on 16 Mar 2020
Edited: Harsha Priya Daggubati
on 16 Mar 2020
Hi,
MATLAB does not support Anaconda Python. To call Python libraries from MATLAB, you need to install a supported version of the reference implementation (CPython) for Python. MATLAB supports versions 2.7, 3.5, and 3.6. You can download CPython from https://www.python.org/downloads/
You can also refer to the following threads in which relatable questions are asked:
I think this approach answers your query: https://www.mathworks.com/matlabcentral/answers/410406-import-numpy-to-matlab?s_tid=answers_rc1-3_p3_Topic
Hope this helps!
1 Comment
Akshay Jajoo
on 9 Sep 2021
@Harsha Priya Daggubati , Support for Matlab 2020A and 2020B is still the same 2.7, 3.5 and 3.6? Where can I find the information about the latest supported versions?
Also, when you say 3.6. Does it mean exactly 3.6 or any 3.6.x will work?
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!