模型可视化难题技术方案,记念一下装了一天终

作者: 网络编程  发布:2019-09-03

纪念一下装了一天终于成功了的 pygraphviz,下装pygraphviz

老师给了我们一个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-infoPKG-INFO
writing top-level names to pygraphviz.egg-infotop_level.txt
writing dependency_links to pygraphviz.egg-infodependency_links.txt
reading manifest file 'pygraphviz.egg-infoSOURCES.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 'docbuild'
writing manifest file 'pygraphviz.egg-infoSOURCES.txt'
installing library code to buildbdist.win-amd64egg
running install_lib
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
C:UsersGJWoodAppDataLocalProgramsCommonMicrosoftVisual C++ for Python9.0VCBinamd64cl.exe /c /nologo /Ox /MD
 /W3 /GS- /DNDEBUG -DGVDLL "-IC:/Program Files (x86)/Graphviz2.38/include" -Ic:UsersGJWoodAnacondainclude -Ic:Users
GJWoodAnacondaPC /Tcpygraphviz/graphviz_wrap.c /Fobuildtemp.win-amd64-2.7Releasepygraphviz/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:UsersGJWoodAppDataLocalProgramsCommonMicrosoftVisual C++ for Python9.0VCBinamd64link.exe /DLL /nologo /IN
CREMENTAL:NO "/LIBPATH:C:/Program Files (x86)/Graphviz2.38/lib/release/lib" /LIBPATH:c:UsersGJWoodAnacondalibs /LIBP
ATH:c:UsersGJWoodAnacondaPCbuildamd64 cgraph.lib cdt.lib /EXPORT:init_graphviz buildtemp.win-amd64-2.7Releasepyg
raphviz/graphviz_wrap.obj /OUT:buildlib.win-amd64-2.7pygraphviz_graphviz.pyd /IMPLIB:buildtemp.win-amd64-2.7Release
pygraphviz_graphviz.lib /MANIFESTFILE:buildtemp.win-amd64-2.7Releasepygraphviz_graphviz.pyd.manifest
graphviz_wrap.obj : warning LNK4197: export 'init_graphviz' specified multiple times; using first specification
   Creating library buildtemp.win-amd64-2.7Releasepygraphviz_graphviz.lib and object buildtemp.win-amd64-2.7Releas
epygraphviz_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
buildlib.win-amd64-2.7pygraphviz_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 FilesEclipsepluginsorg.python.pydev_3.3.3.201401272249pysrcpydevd.py", line 1738, in <module>
    debugger.run(setup['file'], None, None)
  File "D:Program FilesEclipsepluginsorg.python.pydev_3.3.3.201401272249pysrcpydevd.py", line 1355, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:UsersSUUSERworkspaceThreadGraphparseText.py", line 17, in <module>
    G.layout(prog='dot') 
  File "C:Python27libsite-packagespygraphvizagraph.py", line 1305, in layout
    data=self._run_prog(prog,' '.join([args,"-T",fmt]))
  File "C:Python27libsite-packagespygraphvizagraph.py", line 1251, in _run_prog
    runprog=r'"%s"'%self._get_prog(prog)
  File "C:Python27libsite-packagespygraphvizagraph.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.”(

可是我已经装了呀。这是才想起来,是不是还要设置环境变量什么的:我又把C:Program Files (x86)Graphviz2.38bin加到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

pygraphviz,下装pygraphviz 老师给了我们一个python文件让我们看懂,然后里面有一句 import pygraphviz as pgv 为了能...

       keras.utils.vis_utils模块提供了画出Keras模型的函数,依赖于python的两个库pydot、graphviz。

       安装Anaconda的小伙伴可以通过conda install pydot & conda install graphviz安装这两个库,也可以用过pip命令完成安装。但是安装完后运行keras的可视化模型的操作依旧会报错(ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.)。自己明明安装了这两个库为什么依旧报错了。下面教大家在WIn10下的解决方案:

        报错的原因其实不在于pydot,跟python包没有关系,而是因为graphviz需要安装二进制执行文件(跟imagick类似),所以还需要去官网下一个graphviz安装包安装:graphviz二进制执行文件,下载安装graphviz-2.38.msi

图片 1

下载graphviz文件

       下再好一路next就行,不过中间有一个选项选for everyone。安装完成之后就是,在环境变量的path里面添加可执行文件的环境变量,如最后一行所示D:Graphvizbin。

图片 2

环境变量配置

    重启Python IDE即可正常运行。

图片 3

网络流程图

本文由王中王开奖结果发布于网络编程,转载请注明出处:模型可视化难题技术方案,记念一下装了一天终

关键词:

上一篇:Python解释器
下一篇:没有了