Malab Python problem -- isloaded set to 0

조회 수: 18 (최근 30일)
Mahesh
Mahesh 2014년 10월 21일
편집: Robert Snoeberger 2014년 10월 24일
Hi,
I have downloaded the newest Matlab (R2014b) and am trying to call a Python script from my Matlab script. When I run "pyversion" I get this output:
version: '2.7'
executable: '/Applications/anaconda/bin/python2.7'
library: '/Applications/anaconda/lib/libpython2.7.dylib'
home: '/Applications/anaconda'
isloaded: 0
Why is "isloaded" equal to 0, why isn't it loading? I'm not sure how to fix this issue.

채택된 답변

Robert Snoeberger
Robert Snoeberger 2014년 10월 22일
편집: Robert Snoeberger 2014년 10월 24일
The output from "pyversion" looks reasonable. You don't need to explicitly load Python. It will load when it is needed, which is the first time you access the "py" package. Have you tried the example in the documentation?
When MATLAB is started pyversion returns 0 (false) for isloaded. You may still change the version of Python while isloaded is 0 (false). See pyversion documentation. Python loads dynamically upon the first usage of the “py” package. If isloaded is 0 (false) but you believe it should be 1 (true), then see the trouble shooting documentation.
  댓글 수: 2
Mahesh
Mahesh 2014년 10월 22일
Yeah, it seems to be working okay now, thanks!
I have a few other issues however.
When I try to run a python function from my matlab console, I get:
>> py.regression_tests.regression_test Undefined variable "py" or function "py.regression_tests.regression_test".
>> py.regression_tests.regression_test() Undefined variable "py" or class "py.regression_tests.regression_test".
my regression_test function takes in some parameters, but I have seen matlab give an error of "invalid number of errors", and am not getting that here. It does not seem to be find the file for some reason. I am in the directory where the Python script lives.
I also have a short matlab script that I have written which lives in the same directory as the Python script. Here, I create some of the parameters needed for Python, then run the python function. I get this error:
>> regression_tests_python Undefined variable "py" or class "py.regression_tests.regression_test".
Error in regression_tests_python (line 14) coeff_list = py.regression_tests.regression_test(X, row, column, y, test, 0.1);
These errors look like the same issue, it can't find my Python script. How do I fix this?
Robert Snoeberger
Robert Snoeberger 2014년 10월 22일
If you are in the directory where the Python script lives, then you probably need to add the current folder to the Python path. See the example in the documentation:

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by