JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.47k stars 187 forks source link

No output of py"""print('some text')""" in Jupyter Notebooks #738

Open tzxiong opened 4 years ago

tzxiong commented 4 years ago

Hi,

I found that the code mentioned in the title:

using PyCall
py"""
print('some text')
"""

cannot produce the output (nothing has been produced) when running a Julia console or an interactive notebook in the Jupyter Lab.

Any way to solve this?

Thanks, Tianzhu =--==-=

stevengj commented 4 years ago

Basically we have to intercept Python's stdout and redirect it to Julia's stdout in order for this to be captured in the notebook. Should be possible.

lyon-fnal commented 4 years ago

Adding a "+1" to this issue ... would be helpful if this worked. The Python QuTip package prints out useful stuff that I can't see with PyCall.jl in a Jupyter notebook. Thanks!

stevengj commented 4 years ago

Looks like it is sufficient to do:

pyimport("sys")."stdout" = PyTextIO(stdout)
pyimport("sys")."stderr" = PyTextIO(stderr)
lyon-fnal commented 4 years ago

I didn't realize it would be that simple! Thanks very much!!