Matlab won't run python

206 ビュー (過去 30 日間)
Kamala Clark-Swanson
Kamala Clark-Swanson 2015 年 9 月 15 日
コメント済み: Sarvagya 2022 年 7 月 20 日
I call my function and get undefined variable "py" or function "py.sys.path" I enter pyversion and it returns version: ' ' I verified in Add Path that my function paths are correctly listed. And Which -all Python.exe returns the correct path. I have installed this many times but Matlab version 2015a simply won't run my function. I have 64 bit Matlab and 64 bit python and Windows 7 64bit.

回答 (2 件)

Robert Snoeberger
Robert Snoeberger 2015 年 9 月 15 日
編集済み: Robert Snoeberger 2015 年 9 月 16 日
If pyversion returns '', then MATLAB doesn't know where to find your Python installation. You should call pyversion with the path to the python executable [1]. For example, if the executable is located at C:\Python27\python.exe, then call pyversion as follows:
>> pyversion C:\Python27\python.exe
  6 件のコメント
Bo Li
Bo Li 2018 年 12 月 20 日
編集済み: madhan ravi 2018 年 12 月 20 日
Most likely your Python build is statically linked. Python Interface needs the shared library of Python in order to run Python code in MATLAB process. And this is clearly documented:
On Linux® and Mac systems, if you build the Python executable, configure the build with the --enable-shared option.
Reference:

サインインしてコメントする。


Paul Thomas
Paul Thomas 2019 年 2 月 13 日
I first wanted to test if it works in general on my machine and followed the instructions in this video: https://www.youtube.com/watch?v=3D5ym4DvVwo I then got the error "Undefined variable "py" or "class" ...".
This issue was cased by the fact that I had two versions of python installed. One by default from the MAC and Anaconda, which I installed myself. Matlab automatically identified the default version, but using the terminal it only recognized the newer Anaconda version.
So I used the terminal, entered "which python", which showed the path of the Anaconda version and then changed the connected version in Matlab using "pyversion path" and it worked.
I am using macOS Mojave Version 10.14.3 . There might be another way to get the path info, but I am not really familiar with MAC just forced to use it for work.
  3 件のコメント
Sarvagya
Sarvagya 2022 年 7 月 20 日
This worked. Thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by