How to include python calls in compiled Matlab code

조회 수: 5 (최근 30일)
Paul Haney
Paul Haney 2017년 8월 9일
답변: Vaibhav Arora 2019년 4월 6일
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
Jayaram Theegala
Jayaram Theegala 2017년 8월 17일
Does the issue only happen with numpy or with any other packages?

댓글을 달려면 로그인하십시오.

답변 (1개)

Vaibhav Arora
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

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by