WestHealth / pyvis

Python package for creating and visualizing interactive network graphs.
http://pyvis.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
975 stars 165 forks source link

Error in showing network in pyvis_0.3.2 but not in pyvis_0.3.1 #216

Open eivnd opened 1 year ago

eivnd commented 1 year ago

Hello,

I'm running a simple python code for visualising a network. It works fine with pyvis_0.3.1, but with pyvis_0.3.2 I get the following error message when calling

nt = pyvis.Network('100px', '100px')
nt.from_nx(G)  #networkx graph
nt.show('net.html')
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyvis/network.py:546, in Network.show(self, name, local, notebook)
    544 print(name)
    545 if notebook:
--> 546     self.write_html(name, open_browser=False,notebook=True)
    547 else:
    548     self.write_html(name, open_browser=True)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyvis/network.py:515, in Network.write_html(self, name, local, notebook, open_browser)
    513 getcwd_name = name
    514 check_html(getcwd_name)
--> 515 self.html = self.generate_html(notebook=notebook)
    517 if self.cdn_resources == "local":
    518     if not os.path.exists("lib"):

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyvis/network.py:479, in Network.generate_html(self, name, local, notebook)
    476 else:
    477     physics_enabled = self.options.physics.enabled
--> 479 self.html = template.render(height=height,
...
    496                             cdn_resources=self.cdn_resources
    497                             )
    498 return self.html

AttributeError: 'NoneType' object has no attribute 'render'
IsaacShaffer commented 1 year ago

I'm seeing the same issue. When running the basic network demo in the README.md, I get the same error:

g = Network()
g.add_node(0)
g.add_node(1)
g.add_edge(0, 1)
g.show("basic.html")

yields:

basic.html
Traceback (most recent call last):
  File "<pyshell#45>", line 1, in <module>
    g.show("basic.html")
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\pyvis\network.py", line 546, in show
    self.write_html(name, open_browser=False,notebook=True)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\pyvis\network.py", line 515, in write_html
    self.html = self.generate_html(notebook=notebook)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\pyvis\network.py", line 479, in generate_html
    self.html = template.render(height=height,
AttributeError: 'NoneType' object has no attribute 'render'
stefano-ottolenghi commented 1 year ago

Confirmed, same here!

stefano-ottolenghi commented 1 year ago

The issue is probably from this commit https://github.com/WestHealth/pyvis/commit/4c5af7adb840fb6f8b7296c74fab6ecfc7c34e1f#diff-405e696560a2f03a44724592eb5a5cc65a972a257e639619c0a8f88a0069c0b9R536 , where the notebook kwarg was introduced and set to True by default. Calling show with notebook=False fixes the issue indeed. To avoid breaking backwards compatibility, notebook should be set to False in the function definition. Note that inline docs have also been neglected in that commit, the new param is not in the docstring. @BerserkerGaruk