Matlab won't run python
이전 댓글 표시
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
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
댓글 수: 8
Kamala Clark-Swanson
2015년 9월 16일
Kamala Clark-Swanson
2015년 9월 16일
Robert Snoeberger
2015년 9월 16일
편집: Robert Snoeberger
2015년 9월 16일
The error you saw that says the executable is not valid means one or more of the following:
- the path to the executable is incorrect
- you have 32 bit python
To check the path to the executable, enter the following commands into Python.
>>> import sys
>>> print sys.executable
What does it print?
To check that Python is 64 bit, start Python and look at the welcome message. The first line should include either 32 bit or 64 bit. For example, the following welcome message is from a 32 bit Python (version 2.7.3).
Python 2.7.3 (default, Apr 10 2012, 14:24) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or license for more information.
>>>
What is the welcome message when you start Python?
Sahel Fallahdoust
2017년 12월 8일
I have almsot the same problem here! My Matlab which calls some python modules works fine when I'm runnin git within Matlab, but when I make an exe from my Matlab and try to run the exe it gives me "undefined variable "py" or function "py.sys.path" ". I already tried to use pyversion('executable path') in the beginning of my matlab code just in case it can't find the path but this time I get "Error using pyversion Path argument does not specify a valid executable."
Is this problem solved?
michael bronnmann
2018년 10월 25일
exactly the same for me... no solution?
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:
Dumitru MECINEANU
2024년 3월 1일
편집: Dumitru MECINEANU
2024년 3월 1일
I have the same problem...
and yes, I have a 32 bit Python version, but also 32 bit Matlab R2015b and 32 bit Runtime v90 for compiled applications.
some observations and explanations :
- when PYTHONHOME is empty, pythonversion give me one of many installed Python's versions. I can specify the Python's version I need using pyversion('path'). It works in Matlab but not yet in Runtime. and that is the problem, so I tried to set PYTHONHOME, as sugested here : "when running MATLAB apps, an alternative way to set the interpreter is to use the PYTHONHOME environment variable".
- but if PYTHONHOME is specified, pyversion give me an empty answer. And when I try to set him using pyversion('path') it don't works, always the same error : Path argument does not specify a valid executable. I don't understand...
Javier Redondo
2024년 4월 3일
Hi! I am trying to connect python to matlab using pyenv(Version="executable") and I get the following error:
"Error using pyenv
Cannot find shared library for specified Python version. Python must be built with a shared library, and the library must be on the search path"
I have read that it could be solved by using the --enable-shared option in python but I don't know what steps I should follow to do it correctly. Could someone help me? Thanks!
Paul Thomas
2019년 2월 13일
1 개 추천
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
Vincent Hall
2019년 10월 11일
Do you mean "where python"?
Atef
2020년 2월 23일
thanks good.
Sarvagya
2022년 7월 20일
This worked. Thanks
카테고리
도움말 센터 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!