【问题标题】:Result not shown with Visual Studio Code, but correctly shown if using ipython3 (from terminal)结果未在 Visual Studio Code 中显示,但在使用 ipython3 时正确显示(来自终端)
【发布时间】:2021-07-27 21:59:50
【问题描述】:

[已编辑 - 感谢 Ludovico Loreti 的评论]

如果我从 Visual Studio Code 运行以下代码(.py 文件),即按下 VSCode 右上角的绿色三角形按钮“在终端中运行 Python 文件”

from networkit import *  
import networkit as nk 
import matplotlib.pyplot as plt

g = generators.HyperbolicGenerator(1e3).generate()

bc = nk.centrality.Betweenness(g)
bc.run()
bc.ranking()[:10] # the 10 most central nodes

预期结果(即介数计算)不会显示在 VSCode 嵌入式终端中。

相反,如果我直接从终端运行相同的代码,使用 ipython3,结果会很好。

Out[4]: 
[(392, 625118.6896734448),
 (875, 204886.97319625755),
 (170, 121481.35921722073),
 (621, 72627.46666666666),
 (566, 71881.75991032101),
 (37, 62046.49111887374),
 (701, 53157.760291814484),
 (988, 45316.922735729204),
 (934, 42894.204329181564),
 (657, 32147.666666666664)]

为什么?为了在其嵌入式终端中查看我的结果,我应该在 Visual Studio Code 中进行哪些更改?

[P.S.1]:如果我在代码中添加其他命令,例如

print(g.numberOfNodes(), g.numberOfEdges()) 

VSCode 在其嵌入式终端中正确显示结果。因此,看起来(到目前为止)只有与介数相关的结果没有显示/显示。

[P.S.2]:仅供参考,如果有用的话,我已经通过 snap (https://snapcraft.io/install/code/centos) 安装了 Visual Studio Code:

sudo yum install epel-release -y
sudo yum install snapd -y
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap
sudo snap install code --classic

然后我从终端运行 VSCode,输入:

snap run code

【问题讨论】:

  • VSCode 是一个 IDE,你只需要它来编写 Python 代码,运行它当然可以使用终端。 IPython 是一个交互式 shell,但您也可以使用标准的 shell 或 zsh
  • VSCode 在右上角有一个绿色的三角形按钮“在终端中运行 Python 文件”(一种“播放”按钮)。如果按下它,VSCode 将执行/运行您的代码,并在嵌入在 VSCode 中的终端中显示结果,该终端位于编辑器窗口下方。我的代码中与其他命令相关的结果正确显示在 VSCode 的终端中(我没有将它们放在这篇文章中),但与我的文章的对象的介数计算相关的结果却没有。

标签: python visual-studio-code ipython networkit


【解决方案1】:

networkit 论坛中提供了解决方案/说明 https://github.com/networkit/networkit/issues/788

非常感谢 avdgrinten!

【讨论】:

    猜你喜欢
    • 2021-09-05
    • 2021-06-25
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 2022-06-30
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多