Trouble importing Python Modules in MATLAB
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Harsha Priya Daggubati
2020-3-16
编辑:Harsha Priya Daggubati
2020-3-16
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 个评论
Akshay Jajoo
2021-9-9
@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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!