我无法在python 3.9.x中安装PyGraphviz模块

问题描述 投票:0回答:2

我想在我的一个项目中使用图论,这就是为什么我做了一些研究,我发现两个模块对于完成我想做的事情非常有用。 我发现 networkx 模块允许我创建一些图表,但我想创建它们的可视化。这样我就能看到图表。 我找到了另一个适合我的模块,它的名字是 Graphviz。 问题是,当我想在 Python 中运行一个简单的脚本来创建图形并将其可视化时,它说我必须安装 PyGraphviz 模块。 经过多次尝试,没有成功安装。

这是我要运行的Python脚本:

import networkx as nx
from networkx.drawing.nx_agraph import write_dot
import os

# Créer un graphe Escape Game avec NetworkX
G = nx.Graph()
G.add_edge("salle1", "salle2")
G.add_edge("salle2", "salle3")
G.add_edge("salle3", "salle1")

# Exporter le graphe dans un fichier DOT
write_dot(G, "escape_game.dot")

# Utiliser Graphviz pour générer une image du graphe
os.system("dot -Tpng escape_game.dot -o escape_game.png")

这是我得到的错误:

Traceback (most recent call last):
File "C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\networkx\\drawing\\nx_agraph.py", line 133, in to_agraph
import pygraphviz
ModuleNotFoundError: No module named 'pygraphviz'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "c:\\Users\\HP\\Desktop\\Cours_BAC_3\\Projet_individuel\\Juin\\Projet FORM-ESC\\Eg en théorie des graphes\\chatgpt.py", line 12, in \<module\>
write_dot(G, "escape_game.dot")
File "C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\networkx\\drawing\\nx_agraph.py", line 194, in write_dot
A = to_agraph(G)
File "C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\networkx\\drawing\\nx_agraph.py", line 135, in to_agraph
raise ImportError(
ImportError: requires pygraphviz http://pygraphviz.github.io/%60

然后,当我想使用此命令安装 PyGraphviz 模块时:

pip 安装 pygraphviz

这是结果:

Collecting pygraphviz
Using cached pygraphviz-1.10.zip (120 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: pygraphviz
Building wheel for pygraphviz (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─\> \[48 lines of output\]
running bdist_wheel
running build
running build_py
creating build
creating build\\lib.win-amd64-cpython-39
creating build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\agraph.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\graphviz.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\scraper.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\testing.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\__init_\_.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
creating build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_attribute_defaults.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_clear.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_close.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_drawing.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_edge_attributes.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_graph.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_html.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_layout.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_node_attributes.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_readwrite.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_repr_mimebundle.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_scraper.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_string.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_subgraph.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_unicode.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\__init_\_.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
running egg_info
writing pygraphviz.egg-info\\PKG-INFO
writing dependency_links to pygraphviz.egg-info\\dependency_links.txt
writing top-level names to pygraphviz.egg-info\\top_level.txt
reading manifest file 'pygraphviz.egg-info\\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.png' under directory 'doc'
warning: no files found matching '*.txt' under directory 'doc'
warning: no files found matching '*.css' under directory 'doc'
warning: no previously-included files matching '*\~' found anywhere in distribution
warning: no previously-included files matching '\*.pyc' found anywhere in distribution
warning: no previously-included files matching '.svn' found anywhere in distribution
no previously-included directories found matching 'doc\\build'
adding license file 'LICENSE'
writing manifest file 'pygraphviz.egg-info\\SOURCES.txt'
copying pygraphviz\\graphviz.i -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\graphviz_wrap.c -\> build\\lib.win-amd64-cpython-39\\pygraphviz
running build_ext
building 'pygraphviz.\_graphviz' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
\[end of output\]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pygraphviz
Running setup.py clean for pygraphviz
Failed to build pygraphviz
Installing collected packages: pygraphviz
Running setup.py install for pygraphviz ... error
error: subprocess-exited-with-error

× Running setup.py install for pygraphviz did not run successfully.
│ exit code: 1
╰─\> \[50 lines of output\]
running install
C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\setuptools\\command\\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
creating build
creating build\\lib.win-amd64-cpython-39
creating build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\agraph.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\graphviz.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\scraper.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\testing.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\__init_\_.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz
creating build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_attribute_defaults.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_clear.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_close.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_drawing.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_edge_attributes.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_graph.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_html.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_layout.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_node_attributes.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_readwrite.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_repr_mimebundle.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_scraper.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_string.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_subgraph.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\\test_unicode.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
copying pygraphviz\\tests\__init_\_.py -\> build\\lib.win-amd64-cpython-39\\pygraphviz\\tests
running egg_info
writing pygraphviz.egg-info\\PKG-INFO
writing dependency_links to pygraphviz.egg-info\\dependency_links.txt
writing top-level names to pygraphviz.egg-info\\top_level.txt
reading manifest file 'pygraphviz.egg-info\\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.png' under directory 'doc'
warning: no files found matching '*.txt' under directory 'doc'
warning: no files found matching '*.css' under directory 'doc'
warning: no previously-included files matching '*\~' found anywhere in distribution
warning: no previously-included files matching '\*.pyc' found anywhere in distribution
warning: no previously-included files matching '.svn' found anywhere in distribution
no previously-included directories found matching 'doc\\build'
adding license file 'LICENSE'
writing manifest file 'pygraphviz.egg-info\\SOURCES.txt'
copying pygraphviz\\graphviz.i -\> build\\lib.win-amd64-cpython-39\\pygraphviz
copying pygraphviz\\graphviz_wrap.c -\> build\\lib.win-amd64-cpython-39\\pygraphviz
running build_ext
building 'pygraphviz.\_graphviz' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
\[end of output\]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─\> pygraphviz

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

如果有人可以帮助我,或者如果你有另一个Python模块可以完成这项工作,我可以接受。

谢谢!

python-3.x module networkx graphviz pygraphviz
2个回答
0
投票

我在我的项目中成功使用了

import graphviz
。但这可能是一个不同的包。注意:要实际工作,需要安装 GraphViz 应用程序。


0
投票

我设法通过安装 graphwiz 解决了这个问题

sudo apt install graphviz

© www.soinside.com 2019 - 2024. All rights reserved.