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 Center および File ExchangeCall MATLAB from Python についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by