jupyter_client icon indicating copy to clipboard operation
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.

Open aiv-code opened this issue 5 years ago • 3 comments

`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())`

aiv-code avatar May 17 '19 09:05 aiv-code

I will highly appreciate any help of this matter

aiv-code avatar May 18 '19 06:05 aiv-code

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.

MSeal avatar May 28 '19 19:05 MSeal

@jits023 Please check out #477. I do have a similar issue. @MSeal Do you have any thoughts on #477?

hunkim avatar Sep 14 '19 14:09 hunkim