打印未显示在 ipython 笔记本中 [英] Print not showing in ipython notebook

查看:37
本文介绍了打印未显示在 ipython 笔记本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ipython 笔记本 (http://ipython.org/notebook.html) 做一个演示,似乎打印功能不起作用:

I am using ipython notebook (http://ipython.org/notebook.html) to do a demo and it seems like the print function is not working:

为了清晰起见,上图中的命令在此处重写.

The commands in the above picture are rewritten here for clarity.

In [1]: 'hello world'
Out [1]: 'hello world'

In [2]: print 'hello world'

简而言之,[2] 没有打印输出.

In short, there's no print output from the [2].

有谁知道这是否是一个已知的错误?有谁知道如何修复它?

Does anyone know whether it's a known bug? And does anyone know how to fix it?

推荐答案

当我的第一个代码单元是:

I had a similar printing problem when my first code cell was:

import sys
reload(sys)
sys.setdefaultencoding("utf-8")

然后我像这样评论了第二行和第三行:

Then I've commented the second and third lines like this:

import sys
#reload(sys)
#sys.setdefaultencoding("utf-8")

重置内核并重新运行程序,现在我的打印语句可以正常工作了.

Reset the kernel and re-ran the program and now my print statements are working properly.

后来,我发现当我第一次遇到打印问题时,所有打印输出实际上都被发送到 ipython 控制台终端(在我的 Linux 机器上),而不是被嵌入到笔记本中.

Later on, I've found that when I was first having the printing problem, all print outputs were actually being sent to the ipython console terminal (on my Linux box), instead of being embed on the notebook.

这篇关于打印未显示在 ipython 笔记本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆