2014b python from Matlab stdout oddity

2 次查看(过去 30 天)
It appears that when running a python script from within matlab that the python stdout is redirected in some odd way. It does not appear in the matlab session from which the python commands are executed, but instead are redirected in an undefined manner.
For example, I see nothing when I run:
>>py.print('123')
I believe the output is going to a parent process. To see this - start a 2014b session, then within this session start a new matlab session (eg child matlab). Eg.
system('matlab')
Now in the child session, create some python output (enough to cause a flush). eg.
py.print(py.range(int16(1),int16(1000) ))
For me, the output appears in the parent matlab session.
This little hack solves 2 problems for me, first there is no reload() to cause matlab to see changes to python scripts. Reloading matlab is required. 2nd, until now, I've found no way to see python stdout, or stderr.

采纳的回答

Chris Barnhart
Chris Barnhart 2015-1-21
Mathworks ask me to re-install Matlab which fixed this and another problem (no PyException). However, the root causes are likely related to path editing.
I found a file redirectstdout.m located within - C:\Program Files\MATLAB\R2014b\toolbox\matlab\external\interfaces\python\+python\+internal
And PyExceptions lives nearby by: C:\Program Files\MATLAB\R2014b\toolbox\matlab\external\interfaces\python\+matlab\+exception

更多回答(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