python3.6 networkx使用pygraphviz绘图报TypeError

报错如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Traceback (most recent call last):
File "/home/htf/pyproject/sce/ser_con_evo/serconevo/netgraph/__init__.py", line 139, in <module>
main()
File "/home/htf/pyproject/sce/ser_con_evo/serconevo/agent/service_collect_agent.py", line 97, in warper
func(*args, **kwargs)
File "/home/htf/pyproject/sce/ser_con_evo/serconevo/agent/service_collect_agent.py", line 320, in warper
fun(*args, **kwargs)
File "/home/htf/pyproject/sce/ser_con_evo/serconevo/agent/service_collect_agent.py", line 69, in warper
return func(*args, **kwargs)
File "/home/htf/pyproject/sce/ser_con_evo/serconevo/agent/service_collect_agent.py", line 88, in warper
func(*args, **kwargs)
File "/home/htf/pyproject/sce/ser_con_evo/serconevo/netgraph/__init__.py", line 124, in main
A.draw('pyv.png', format='png')
File "/home/htf/pyproject/sce/lib/python3.6/site-packages/pygraphviz/agraph.py", line 1474, in draw
data = self._run_prog(prog, args)
File "/home/htf/pyproject/sce/lib/python3.6/site-packages/pygraphviz/agraph.py", line 1338, in _run_prog
warnings.warn(b"".join(errors), RuntimeWarning)
TypeError: cannot use a string pattern on a bytes-like object

查了下使用的networkx版本,networkx (1.11),networkx在2.0版本才开始支持3.6,怀疑版本问题

NetworkX 2.0

Release date: TBD

Support for Python 3.6 added, drop support for Python 3.3.

1
2
3
4
5
6
7
8
9
10
11
12
13
(sce) htf@linux-rzt3:~/pyproject/sce/ser_con_evo/serconevo/netgraph> pip install networkx==2.0rc1
Collecting networkx==2.0rc1
Using cached networkx-2.0rc1.zip
Requirement already satisfied: decorator>=4.1.0 in /home/htf/pyproject/sce/lib/python3.6/site-packages (from networkx==2.0rc1)
Building wheels for collected packages: networkx
Running setup.py bdist_wheel for networkx ... done
Stored in directory: /home/htf/.cache/pip/wheels/c9/28/7a/00a40c74cd75194c6997fa7a58f99a6029f0dcb3f2d94ba0da
Successfully built networkx
Installing collected packages: networkx
Found existing installation: networkx 1.11
Uninstalling networkx-1.11:
Successfully uninstalled networkx-1.11
Successfully installed networkx-2.0rc1

升级完后发现还是报错,查看报错信息,觉得还是跟pygraphviz有关系,升级到最新的1.4rc1,升级进要指定一些参数.
默认–library-path获取到的为None,我手工指定路径

1
pip install pygraphviz==1.4rc1 --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib64/graphviz/

再次执行.成功出图.

坚持原创技术分享,您的支持将鼓励我继续创作!