老师给了我们一个python文件让我们看懂,然后里面有一句
import pygraphviz as pgv为了能让程序在自己的电脑上,跑起来,我像往常一样,用pip install pygraphviz 来安装,然后,另人苦逼的是各种报错哇。然后在github 下载了包(https://github.com/pygraphviz),解压后用python setup.py install 报错,内容为 fatal error: graphviz/cgraph.h: No such file然后在stackoverflow 上找到的解决办法是编辑setup.py文件中添加这些位置作为目录 :
include_dirs = ‘C:/Program Files (x86)/Graphviz2.38/include‘ library_dirs = ‘C:/Program Files (x86)/Graphviz2.38/lib‘
同时我在readme里面看到,这个需要和Graphviz软件一起使用,而我并没有下载,好滴吧,先到官网上下载了Graphviz-2.38
并且添加了目录再次 install
然后错误变得更多了:
$ python setup.py install library_dirs=C:/Program Files (x86)/Graphviz2.38/lib/release/lib include_dirs=C:/Program Files (x86)/Graphviz2.38/include running install running bdist_egg running egg_info writing pygraphviz.egg-info\PKG-INFO writing top-level names to pygraphviz.egg-info\top_level.txt writing dependency_links to pygraphviz.egg-info\dependency_links.txt reading manifest file ‘pygraphviz.egg-info\SOURCES.txt‘ reading manifest template ‘MANIFEST.in‘ 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‘ writing manifest file ‘pygraphviz.egg-info\SOURCES.txt‘ installing library code to build\bdist.win-amd64\egg running install_lib running build_py running build_ext building ‘pygraphviz._graphviz‘ extension C:\Users\GJWood\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DGVDLL "-IC:/Program Files (x86)/Graphviz2.38/include" -Ic:\Users\GJWood\Anaconda\include -Ic:\Users \GJWood\Anaconda\PC /Tcpygraphviz/graphviz_wrap.c /Fobuild\temp.win-amd64-2.7\Release\pygraphviz/graphviz_wrap.obj graphviz_wrap.c pygraphviz/graphviz_wrap.c(3295) : warning C4267: ‘=‘ : conversion from ‘size_t‘ to ‘int‘, possible loss of data pygraphviz/graphviz_wrap.c(3313) : warning C4267: ‘=‘ : conversion from ‘size_t‘ to ‘int‘, possible loss of data pygraphviz/graphviz_wrap.c(3321) : warning C4047: ‘return‘ : ‘int‘ differs in levels of indirection from ‘Agsym_t *‘ pygraphviz/graphviz_wrap.c(3407) : warning C4101: ‘mode_byte_obj1‘ : unreferenced local variable pygraphviz/graphviz_wrap.c(3406) : warning C4101: ‘mode_obj1‘ : unreferenced local variable pygraphviz/graphviz_wrap.c(3408) : warning C4101: ‘mode1‘ : unreferenced local variable pygraphviz/graphviz_wrap.c(3405) : warning C4101: ‘fd1‘ : unreferenced local variable pygraphviz/graphviz_wrap.c(3466) : warning C4101: ‘mode2‘ : unreferenced local variable pygraphviz/graphviz_wrap.c(3464) : warning C4101: ‘mode_obj2‘ : unreferenced local variable pygraphviz/graphviz_wrap.c(3463) : warning C4101: ‘fd2‘ : unreferenced local variable pygraphviz/graphviz_wrap.c(3465) : warning C4101: ‘mode_byte_obj2‘ : unreferenced local variable C:\Users\GJWood\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\link.exe /DLL /nologo /IN CREMENTAL:NO "/LIBPATH:C:/Program Files (x86)/Graphviz2.38/lib/release/lib" /LIBPATH:c:\Users\GJWood\Anaconda\libs /LIBP ATH:c:\Users\GJWood\Anaconda\PCbuild\amd64 cgraph.lib cdt.lib /EXPORT:init_graphviz build\temp.win-amd64-2.7\Release\pyg raphviz/graphviz_wrap.obj /OUT:build\lib.win-amd64-2.7\pygraphviz\_graphviz.pyd /IMPLIB:build\temp.win-amd64-2.7\Release \pygraphviz\_graphviz.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\pygraphviz\_graphviz.pyd.manifest graphviz_wrap.obj : warning LNK4197: export ‘init_graphviz‘ specified multiple times; using first specification Creating library build\temp.win-amd64-2.7\Release\pygraphviz\_graphviz.lib and object build\temp.win-amd64-2.7\Releas e\pygraphviz\_graphviz.exp graphviz_wrap.obj : error LNK2019: unresolved external symbol agsafeset referenced in function agsafeset_label graphviz_wrap.obj : error LNK2019: unresolved external symbol agstrdup_html referenced in function agsafeset_label graphviz_wrap.obj : error LNK2019: unresolved external symbol agattr referenced in function agattr_label graphviz_wrap.obj : error LNK2019: unresolved external symbol agopen referenced in function _wrap_agopen graphviz_wrap.obj : error LNK2019: unresolved external symbol agclose referenced in function _wrap_agclose graphviz_wrap.obj : error LNK2019: unresolved external symbol agread referenced in function _wrap_agread graphviz_wrap.obj : error LNK2019: unresolved external symbol agwrite referenced in function _wrap_agwrite graphviz_wrap.obj : error LNK2019: unresolved external symbol agisundirected referenced in function _wrap_agisundirected graphviz_wrap.obj : error LNK2019: unresolved external symbol agisdirected referenced in function _wrap_agisdirected graphviz_wrap.obj : error LNK2019: unresolved external symbol agisstrict referenced in function _wrap_agisstrict graphviz_wrap.obj : error LNK2019: unresolved external symbol agnode referenced in function _wrap_agnode graphviz_wrap.obj : error LNK2019: unresolved external symbol agidnode referenced in function _wrap_agidnode graphviz_wrap.obj : error LNK2019: unresolved external symbol agsubnode referenced in function _wrap_agsubnode graphviz_wrap.obj : error LNK2019: unresolved external symbol agfstnode referenced in function _wrap_agfstnode graphviz_wrap.obj : error LNK2019: unresolved external symbol agnxtnode referenced in function _wrap_agnxtnode graphviz_wrap.obj : error LNK2019: unresolved external symbol aglstnode referenced in function _wrap_aglstnode graphviz_wrap.obj : error LNK2019: unresolved external symbol agprvnode referenced in function _wrap_agprvnode graphviz_wrap.obj : error LNK2019: unresolved external symbol agedge referenced in function _wrap_agedge graphviz_wrap.obj : error LNK2019: unresolved external symbol agidedge referenced in function _wrap_agidedge graphviz_wrap.obj : error LNK2019: unresolved external symbol agsubedge referenced in function _wrap_agsubedge graphviz_wrap.obj : error LNK2019: unresolved external symbol agfstin referenced in function _wrap_agfstin graphviz_wrap.obj : error LNK2019: unresolved external symbol agnxtin referenced in function _wrap_agnxtin graphviz_wrap.obj : error LNK2019: unresolved external symbol agfstout referenced in function _wrap_agfstout graphviz_wrap.obj : error LNK2019: unresolved external symbol agnxtout referenced in function _wrap_agnxtout graphviz_wrap.obj : error LNK2019: unresolved external symbol agfstedge referenced in function _wrap_agfstedge graphviz_wrap.obj : error LNK2019: unresolved external symbol agnxtedge referenced in function _wrap_agnxtedge graphviz_wrap.obj : error LNK2019: unresolved external symbol agattrsym referenced in function _wrap_agattrsym graphviz_wrap.obj : error LNK2019: unresolved external symbol agnxtattr referenced in function _wrap_agnxtattr graphviz_wrap.obj : error LNK2019: unresolved external symbol agget referenced in function _wrap_agget graphviz_wrap.obj : error LNK2019: unresolved external symbol agxget referenced in function _wrap_agxget graphviz_wrap.obj : error LNK2019: unresolved external symbol agset referenced in function _wrap_agset graphviz_wrap.obj : error LNK2019: unresolved external symbol agxset referenced in function _wrap_agxset graphviz_wrap.obj : error LNK2019: unresolved external symbol agsubg referenced in function _wrap_agsubg graphviz_wrap.obj : error LNK2019: unresolved external symbol agfstsubg referenced in function _wrap_agfstsubg graphviz_wrap.obj : error LNK2019: unresolved external symbol agnxtsubg referenced in function _wrap_agnxtsubg graphviz_wrap.obj : error LNK2019: unresolved external symbol agparent referenced in function _wrap_agparent graphviz_wrap.obj : error LNK2019: unresolved external symbol agroot referenced in function _wrap_agroot graphviz_wrap.obj : error LNK2019: unresolved external symbol agdelsubg referenced in function _wrap_agdelsubg graphviz_wrap.obj : error LNK2019: unresolved external symbol agnnodes referenced in function _wrap_agnnodes graphviz_wrap.obj : error LNK2019: unresolved external symbol agnedges referenced in function _wrap_agnedges graphviz_wrap.obj : error LNK2019: unresolved external symbol agdegree referenced in function _wrap_agdegree graphviz_wrap.obj : error LNK2019: unresolved external symbol agraphof referenced in function _wrap_agraphof graphviz_wrap.obj : error LNK2019: unresolved external symbol agnameof referenced in function _wrap_agnameof graphviz_wrap.obj : error LNK2019: unresolved external symbol agdelnode referenced in function _wrap_agdelnode graphviz_wrap.obj : error LNK2019: unresolved external symbol agdeledge referenced in function _wrap_agdeledge graphviz_wrap.obj : error LNK2019: unresolved external symbol Agdirected referenced in function Swig_var_Agdirected_get graphviz_wrap.obj : error LNK2019: unresolved external symbol Agstrictdirected referenced in function Swig_var_Agstrictd irected_get graphviz_wrap.obj : error LNK2019: unresolved external symbol Agundirected referenced in function Swig_var_Agundirected_ get graphviz_wrap.obj : error LNK2019: unresolved external symbol Agstrictundirected referenced in function Swig_var_Agstric tundirected_get build\lib.win-amd64-2.7\pygraphviz\_graphviz.pyd : fatal error LNK1120: 49 unresolved externals error: command ‘C:\\Users\\GJWood\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd 64\\link.exe‘ failed with exit status 1120
这时候我才想起,可以到http://www.lfd.uci.edu/~gohlke/pythonlibs/直接下载.whl文件哇。下载并安装
pip install pygraphviz?1.3.1?cp27?none?win_amd64.whl
成功啦
然而这并没有结束
当我试着打了如下代码,并运行时:
import pygraphviz as pgv G=pgv.AGraph(strict=False,directed=True) G.add_node(‘a‘) G.add_node(‘b‘) G.add_edge(‘b‘,‘c‘) nodelist=[‘f‘,‘g‘,‘h‘] G.add_nodes_from(nodelist) #attributes G.graph_attr[‘label‘]="simple nodes and edge" G.node_attr[‘shape‘]=‘circle‘ G.edge_attr[‘color‘]=‘red‘ s=G.to_string() G.write("first.dot") G.layout(prog=‘dot‘) G.draw(‘first.png‘)
它依旧报错
Traceback (most recent call last): File "D:\Program Files\Eclipse\plugins\org.python.pydev_3.3.3.201401272249\pysrc\pydevd.py", line 1738, in <module> debugger.run(setup[‘file‘], None, None) File "D:\Program Files\Eclipse\plugins\org.python.pydev_3.3.3.201401272249\pysrc\pydevd.py", line 1355, in run pydev_imports.execfile(file, globals, locals) # execute the script File "D:\Users\SUUSER\workspace\ThreadGraph\parseText.py", line 17, in <module> G.layout(prog=‘dot‘) File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1305, in layout data=self._run_prog(prog,‘ ‘.join([args,"-T",fmt])) File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1251, in _run_prog runprog=r‘"%s"‘%self._get_prog(prog) File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1239, in _get_prog raise ValueError("Program %s not found in path."%prog) ValueError: Program dot not found in path.
查到的资料说“PyGraphviz doesn‘t work without Graphviz. Install that too.”(http://stackoverflow.com/questions/13987353/python-valueerror-program-dot-not-found-in-path?rq=1)
可是我已经装了呀。这是才想起来,是不是还要设置环境变量什么的:我又把C:\Program Files (x86)\Graphviz2.38\bin加到PATH里去
关了pycharm,重开,运行,OK,不报错了
最后的最后,放出相关下载链接
graphviz-2.38.msi链接:http://pan.baidu.com/s/1nu4wcgp 密码:zazz
pygraphviz?1.3.1?cp27?none?win_amd64.whl链接:http://pan.baidu.com/s/1c1nJyKg 密码:wra9
时间: 2024-10-28 22:39:58