【问题标题】:Running Graph library with nodebox on windows + None Type Error在 Windows 上使用 nodebox 运行图形库 + 无类型错误
【发布时间】:2011-09-02 22:49:05
【问题描述】:

我已经在我的机器上安装了 nodebox 2 for windows,并验证了所有示例都按原样运行。

现在我想使用图形库Graph 来做同样的事情。

我将它复制到我的站点包文件夹中,然后在 IDLE 中运行它提供的示例。

我收到 ximport 的错误。所以我在代码中添加了from nodebox.graphics import *

现在我收到以下错误

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'

有什么方法可以在 windows 的 nodebox 之外运行这个库?

谢谢...

我正在粘贴下面出现错误的代码...

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)

【问题讨论】:

    标签: python nodebox


    【解决方案1】:

    Nodebox Graph docs mention,它支持 Nodebox 1.9.5.6,这是一个 Nodebox 1(仅限 Mac)版本号。据我所知,Graph 库尚未移植到 Nodebox 2,因此目前只能在 Mac 上运行。


    一个选项是一个名为 Nodebox OpenGL 的项目,它实现了 Nodebox API 并包含自己的图形库,在examples\08-physics\07-graph 下有一个使用它的示例。 Nodebox 1 图形库尚不兼容,但它包含自己的图形类nodebox.graphics.physics.Graph

    要使用它,您需要下载:

    解压这些并安装,或者只是将nodeboxpyglet 包放在你的Python 路径(site-packages) 的某个位置。当您运行 07-graph.py 时,您应该会看到:

    【讨论】:

    • 这个答案有一个小问题,它为 Mac OS X 用户提供了指导,而问卷将他的操作系统指定为 Windows。
    • 是的,Graph 库的提及让我大吃一惊——它只在 Mac 上运行。使用该信息和解决方法更新了答案。
    猜你喜欢
    • 2011-06-24
    • 2018-05-01
    • 1970-01-01
    • 2022-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 2014-07-28
    相关资源
    最近更新 更多