How to call python in Matlab?

1 次查看(过去 30 天)
Sheng Liu
Sheng Liu 2017-12-11
回答: Khushboo 2022-10-27
This is supposed to be simple because seems no one has this problem. I was told to run this code
py.numpy.zeros([3,3])
in Matlab. But it returns error: Undefined variable "py" or class "py.numpy.zeros".
I installed Python 3.5.3 it doesn't work. Then I tried Python 2.7, also doesn't work. Is there anything special I need to do. BTW, I am using Matlab 2017.
Thank you.

回答(1 个)

Khushboo
Khushboo 2022-10-27
Hello,
I hope you have done the necessary setup for using Python in MATLAB and imported numpy in your MATLAB code using the following:
py.importlib.import_module('numpy')
More details regarding import can be found here.
Otherwise, it might be an issue with the setup. It would be better to install Python (Cpython) and make sure that numpy library is installed. Then you can launch MATLAB and make sure that MATLAB has loaded Python using the following:
pyversion
If this does not work, it would be really helpful if you could give more details regarding your environment (if you are using Anaconda) and path setup.

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by