How to include python calls in compiled Matlab code

7 views (last 30 days)
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.

Answers (1)

Vaibhav Arora
Vaibhav Arora on 6 Apr 2019
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

Community Treasure Hunt

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

Start Hunting!