How to include python calls in compiled Matlab code
4 次查看(过去 30 天)
显示 更早的评论
I'm trying to deploy a standalone Matlab application that calls python. Below is a simple example:
function pytest
pyversion
fprintf('%g\n',py.numpy.exp(1))
end
The codes runs fine at the Matlab command prompt, and also successfully runs as an executable on the machine I used to compile the code. When I try to run the executable on another machine, I get the output / error:
version: '3.5'
executable: 'C:\Program Files\Anaconda3\python.EXE'
library: 'C:\Program Files\Anaconda3\python35.dll'
home: 'C:\Program Files\Anaconda3'
isloaded: 1
Undefined variable “py” or class “py.numpy.exp”
I’m confused because the on the remote machine, the output of the “pyversion” command is as expected, indicating that matlab knows where python is. However it throws an error when trying to call a python function.
Some more info: I’m using Matlab 2016b (compiler ver 6.3). Both machines are running 64-bit windows 7. Both machines have the same python distribution (python 3.5 with anaconda 4.2), in the same location. Both machines successfully run executables without python calls.
1 个评论
回答(1 个)
Vaibhav Arora
2019-4-6
Install Python (Cpython) from python.org/downloads.
Make sure the version you download is 64-bit if your Matlab exe is 64-bit. By default, a 32-bit cersion of python is downloaded so be careful.
Open python and try the command "import numpy as np". If you get an error, you need to install the library. For this, go to command prompt and type (for python 3): "pip3 install numpy"
Now you will be able to use numpy library in matlab
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call MATLAB from Python 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!