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

yzuktlbb  于 2023-02-26  发布在  Python
关注(0)|答案(1)|浏览(289)

我想在我的一个项目中使用图论,这就是为什么我做了一些研究,我发现两个模块非常有用,可以做我想做的事情。我发现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模块时:
管道安装
结果如下:

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模块来做这项工作,我可以接受。
谢谢!

v64noz0r

v64noz0r1#

我在我的项目中成功地使用了import graphviz,但那可能是一个不同的包。要真正工作,它需要安装GraphViz应用程序。

相关问题