如何将网络从graphviz.dot转换为Networkx?

时间:2019-05-21 19:05:04

标签: python-3.x pycharm networkx

我必须将网络转换成graphviz.dot以networkx格式,因为我必须将其导入到node2vec中并创建随机游走。这是我运行的代码,但是它总是给我相同的错误,我使用的是Windows 10,pycharm和python 3.7。可能我无法安装“ Pygraphviz”软件包。错误是: ImportError: DLL load failed: %1 non è un'applicazione di Win32 valida

from networkx.drawing import nx_agraph
from node2vec import Node2Vec
try:
   import pygraphviz
except ImportError:
   raise ImportError('read_dot() requires pygraphviz ',
                     'http://pygraphviz.github.io/')


#dotFormat = pydot.graph_from_dot_file('./P1Main.dot')
dotFormat = r"C:\Users\Admin1\P1Main.dot"

A = pygraphviz.AGraph(file=dotFormat)
G = nx_agraph.from_agraph(A)
# Precompute probabilities and generate walks - **ON WINDOWS ONLY WORKS
# WITH workers=1**
# Use temp_folder for big graphs
node2vec = Node2Vec(G, dimensions=64, walk_length=3, num_walks=2, workers=1)

# Embed nodes
# Any keywords acceptable by gensim.Word2Vec can be passed, `diemnsions`
# and `workers` are automatically passed (from the Node2Vec constructor)
model = node2vec.fit(window=10, min_count=1, batch_words=4)


# Save embeddings for later use
model.wv.save_word2vec_format('Random_Walk')

# Save model for later use
model.save('Random_MODEL_Walk')
``

0 个答案:

没有答案