在 pyvis 中我总是得到这个错误:“AttributeError: 'NoneType' object has no attribute 'render'”

问题描述 投票:0回答:1

我想用最新版本的pyvis和python 3.9.6版本做一个网络可视化:

from pyvis.network import Network
g = Network()
g.add_node(0)
g.add_node(1)
g.add_edge(0, 1)
g.show('test.html')

每次我执行

g.show()
我得到这个错误:

Traceback (most recent call last):
  File "/Users/tom/Library/Mobile Documents/com~apple~CloudDocs/Projekte/Coding_/f1 standings/test2.py", line 3, in <module>
    g.show('nx.html')
  File "/Users/tom/Library/Python/3.9/lib/python/site-packages/pyvis/network.py", line 546, in show
    self.write_html(name, open_browser=False,notebook=True)
  File "/Users/tom/Library/Python/3.9/lib/python/site-packages/pyvis/network.py", line 515, in write_html
    self.html = self.generate_html(notebook=notebook)
  File "/Users/tom/Library/Python/3.9/lib/python/site-packages/pyvis/network.py", line 479, in generate_html
    self.html = template.render(height=height,
AttributeError: 'NoneType' object has no attribute 'render'

我尝试更新 pyvis,我更改了代码中的各种细节,我导入了所有 pyvis.network,但没有任何结果。

python python-3.x networkx attributeerror pyvis
1个回答
0
投票

默认

self.template = None
。您必须使用
Network().set_template

设置此值
© www.soinside.com 2019 - 2024. All rights reserved.