输出显示在 Jupyter Notebook 中但不在 PyCharm 中 [英] Output shown in Jupyter Notebook but not in PyCharm

查看:67
本文介绍了输出显示在 Jupyter Notebook 中但不在 PyCharm 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过类似的帖子,但没有看到任何真正解决 Jupyter Notebook 和 PyCharm 之间输出差异的回复.

I've seen similar posts but haven't seen any reply that really addresses the difference in outputs between Jupyter Notebook and PyCharm.

一个例子是这样的:

from datetime import datetime
now = datetime.now()
now

输出:
Jupyter notebook:datetime.datetime(2019, 12, 8, 13, 20, 37, 339795)

Pycharm:进程以退出代码 0 结束

PyCharm 中没有显示输出.有人可以解释为什么这两者的输出不同吗?有什么办法可以在 PyCharm 中看到相同的输出?

There is no output shown in PyCharm. Could someone please explain why there is a difference in the outputs of these two? Any way I can see the same output in PyCharm?

推荐答案

原因是因为 Pycharm 在脚本模式下运行,而 Jupyter 在交互模式下工作.可以添加打印语句如 print(now) 来查看输出,也可以在 Pycharm 交互式解释器中运行代码.

The reason is because Pycharm is running in script mode, while Jupyter is working in interactive mode. You can add print statements such as print(now) to see the output, or you can run the code in the Pycharm interactive interpreter.

有关交互模式的更多详细信息,请参见此处交互模式和脚本模式下的 Python 解释差异

See this for more details on interactive mode Python interpretation difference in interactive mode and script mode

有关如何使用 Pycharm 交互式解释器的更多详细信息,请参阅此处Pycharm 是否具有交互式 Python 解释器?

See this for more details on how to use the Pycharm interactive interpreter Does Pycharm have Interactive Python Interpreter?

这篇关于输出显示在 Jupyter Notebook 中但不在 PyCharm 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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