开发者

Running Graph library with nodebox on windows + None Type Error

I have installed nodebox 2 for windows on my machine and have verified that all the examples are running as it is.

Now i want to use graph library Graph for the same.

I went and copied it as it is in my site-packages folder and then ran the examples it had given along it in IDLE.

I recieved an error of ximport . So then i added in the code as from nodebox.graphics import *

Now i get the following error

Traceback (most recent call last):

File "C:\Python26\Lib\site-packages\graph\graph_example2.py", line 39, in <module> g.draw(highlight=path, weighted=True, directed=True)

File "C:\Python26\lib\site-packages\graph\__init__.py", line 453, in draw self.update()

File "C:\Python26\lib\site-packages\graph\__init__.py", line 416, in update self.x = _ctx.WIDTH - max.x*self.d - min_.x*self.d

AttributeError: 'NoneType' object has no attribute 'WIDTH'

Is there any way I can run this library from outside of nodebox in windows ?

thanks...

I am pasting the code for which i get the error below...

from nodebox.graphics import *
try:
    graph = ximport("graph")
except ImportError:
    graph = ximport("__init__")
    reload(graph)

size(开发者_如何学运维600, 600)

# A graph object.
g = graph.create(iterations=500, distance=1.0)

# Add nodes with a random id,
# connected to other random nodes.
for i in range(50):
    node1 = g.add_node(random(500))
    if random() > 0.5:
        for i in range(choice((2, 3))):
             node2 = choice(g.nodes)
             g.add_edge(node1.id, node2.id, weight=random())

# We leave out any orphaned nodes.
g.prune()

# Colorize nodes.
# Nodes with higher importance are blue.
g.styles.apply()

# Update the graph layout until it's done.
g.solve()

# Show the shortest path between two random nodes.
path = []
id1 = choice(g.keys())
id2 = choice(g.keys())
path = g.shortest_path(id1, id2)

# Draw the graph and display the shortest path.
g.draw(highlight=path, weighted=True, directed=True)


The Nodebox Graph docs mention that it supports Nodebox 1.9.5.6, which is a Nodebox 1 (Mac only) version number. To my knowledge the Graph library has not yet been ported to Nodebox 2, so can only currently run on the Mac.


One option is a project called Nodebox OpenGL which implements the Nodebox API and includes its own graph library, with an example of using it under examples\08-physics\07-graph. The Nodebox 1 Graph library is not yet compatible, but it includes its own graph class nodebox.graphics.physics.Graph.

To use it, you'll need to download:

  • Nodebox for OpenGL
  • pyglet cross platform multimedia library

Extract these and install, or just place the nodebox and pyglet packages somewhere on your Python path (site-packages). When you run 07-graph.py you should see this:

Running Graph library with nodebox on windows + None Type Error

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜