How to include python calls in compiled Matlab code

8 visualizaciones (últimos 30 días)
Paul Haney
Paul Haney el 9 de Ag. de 2017
Respondida: Vaibhav Arora el 6 de Abr. de 2019
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 comentario
Jayaram Theegala
Jayaram Theegala el 17 de Ag. de 2017
Does the issue only happen with numpy or with any other packages?

Iniciar sesión para comentar.

Respuestas (1)

Vaibhav Arora
Vaibhav Arora el 6 de Abr. de 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

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by