jupyter_client
jupyter_client copied to clipboard
0 I am trying to execute python code using jupyter_client execute a method and expect result as an image (base64) instead I am getting Object.
`from jupyter_client import KernelManager
import time
try:
from queue import Empty # Py 3
except ImportError:
from Queue import Empty # Py 2
#km = KernelManager(kernel_name='ir') km = KernelManager(kernel_name='python3') km.start_kernel() print (km.is_alive()) try: c = km.client() msg_id=c.execute('from matplotlib import pyplot as plt;plt.plot([1,2,3],[4,5,1]);plt.show()') #msg_id=c.execute('x <- c(21, 62, 10, 53);labels <- c("London", "New York", "Singapore", "Mumbai");pie(x,labels)') state='busy' data={} while state!='idle' and c.is_alive(): try: msg=c.get_iopub_msg(timeout=100) if not 'content' in msg: continue content = msg['content'] if 'data' in content: data=content['data'] if 'execution_state' in content: state=content['execution_state'] except Empty: pass except KeyboardInterrupt: pass finally: km.shutdown_kernel() print (km.is_alive())`
I will highly appreciate any help of this matter
This is more of an ipython question for why you don't get the image/png
mimetype here, but essentially when you execute code the kernel responses coming back will provide any mimetypes you either specify or default to ones that the object made available. In particular image/png
and text/plain
are both mime types in the "content" object's "data" key. Your application is then able to select the rendering appropriate out of the mimetype responses.
@jits023 Please check out #477. I do have a similar issue. @MSeal Do you have any thoughts on #477?