py.os.popen error under Windows

조회 수: 9 (최근 30일)
Xiangrui Li
Xiangrui Li 2017년 6월 17일
댓글: maho 2019년 7월 16일
Later matlab versions can call python libraries directly. I came across a problem when calling py.os.popen or py.subprocess.check_output. From the error message below, os.popen() seems calling subprocess:
h = py.os.popen('dir');
Error using subprocess>_make_inheritable (line 948)
Python Error: OSError: [WinError 6] The handle is invalid
Error in subprocess>_get_handles (line 898)
p2cread = self._make_inheritable(p2cread)
Error in subprocess>__init__ (line 665)
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
Error in os>popen (line 978)
bufsize=buffering)
More info about the system: Matlab 2017a under Windows 7, python 3.6.
There is no error under Linux with python 2.7.6, matlab R2015a.

답변 (1개)

Nagarjuna Manchineni
Nagarjuna Manchineni 2017년 6월 20일
To call Python libraries from MATLAB, you need to install a supported version of the reference implementation (CPython) for Python. MATLAB R2017a supports versions 2.7, 3.4, and 3.5.
I tried the same command on MATLAB R2017a with Python version 3.5 and everything worked fine. I would recommend to use the supported version of Python (3.5).
See the following documentation page for more reference:
  댓글 수: 2
Xiangrui Li
Xiangrui Li 2017년 6월 20일
Thanks for answering. But that does not seem to be the cause. Could something else be wrong on my Windows 7 system?
disp(pyversion)
3.5
h = py.os.popen('dir');
Error using subprocess>_make_inheritable (line 913)
Python Error: OSError: [WinError 6] The handle is invalid
Error in subprocess>_get_handles (line 863)
p2cread = self._make_inheritable(p2cread)
Error in subprocess>__init__ (line 640)
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
Error in os>popen (line 1035)
bufsize=buffering)
maho
maho 2019년 7월 16일
Having the same problem on python 3.7

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

카테고리

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