我正在尝试使用jupyter_client执行python代码来执行一个方法,并将结果期望为图像(base64),而不是我得到了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
# print(msg)
print (data)
except KeyboardInterrupt:
pass
finally:
km.shutdown_kernel()
print (km.is_alive())
我期待图像但是得到'