I want to do a network visualisation using pyvis in the latest version and the python version 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')
every time I execute g.show()
i get this error:
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'
I tried updating pyvis, I changed all sorts of details in my code and I imported all of pyvis.network without any results.
In 0.3.2 that gets pushed to pip, for some reason the Network
.show()
function have notebook=True
as default, even though the Network()
constructor has notebook=False
as default. I changed my show function and specify notebook=False
then it works properly again.
https://github.com/WestHealth/pyvis/blob/ccb7ce745ee4159ce45eac70b9848ab965fc0906/pyvis/network.py#L537
from pyvis.network import Network
g = Network()
g.add_node(0)
g.add_node(1)
g.add_edge(0, 1)
g.show('test.html', notebook=False)
I was able to fix a similar issue, where I was running pyvis with networkx in a Jupyter Notebook.
from pyvis import network as net
import networkx as nx
#%%
g=net.Network()
nxg = nx.complete_graph(5)
g.from_nx(nxg)
#%%
g.show("example.html")
AttributeError: 'NoneType' object has no attribute 'render'
When initializing the Network, I added notebook=True
, this fixed the issue for me. The new code is:
from pyvis import network as net
import networkx as nx
#%%
g=net.Network(notebook=True)
nxg = nx.complete_graph(5)
g.from_nx(nxg)
#%%
g.show("example.html")
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With