Anaconda 환경에서 Graphviz 사용
개요
Graphviz를 Anaconda 환경에서 사용하는 분은 conda 프롬프트로 설치하는 것만으로 좋았기 때문에 절차를 정리했습니다.
※그 외의 환경에서 사용하고 싶은 경우는, 이하를 참조해 주세요.
【Windows10】Graphviz 설치
패키지 설치
conda install python-graphviz
환경 변수 설정
bin까지의 경로를 환경 변수에 설정합니다.
...\Anaconda3\pkgs\graphviz-2.38-hfd603c8_2\Library\bin
※환경 변수의 추가 방법을 모르는 경우는 여기 를 참조해 주십시오.
참고: 확인을 눌러 환경 변수 화면을 제대로 닫습니다. 패스가 통과하지 않고 1 시간 정도 고민했다 
확인
DOT 명령을 사용할 수 있는지 확인
명령 프롬프트에서 다음을 수행합니다.
dot -V
// 以下が出力されればOK
dot - graphviz version 2.38.0 (20140413.2041)
DOT 언어로 확인하기
메모장 등으로 dot 파일을 만듭니다.
sample.dotdigraph g{
1 [label="x0", color=orange, style=filled]
2 [label="x1", color=orange, style=filled]
3 [label="Add", color=lightblue, style=filled, shape=box]
4 [label="y", color=orange, style=filled]
1 -> 3 [label="2"]
2 -> 3 [label="3"]
3 -> 4 [label="5"]
}
명령 프롬프트에서 다음을 수행합니다.
dot sample.dot -T png -o sample.png
sample.dot : 소스가되는 dot 파일
-T png : 렌더링할 확장자의 지정(pdf나 svg등에도 할 수 있다)
-o sample.png : 출력 파일

sample.png
Python 스크립트로 확인
test\test.pyfrom graphviz import Digraph
G = Digraph(format="png")
G.attr("node", shape="square", style="filled")
G.edge("start","state1",label="0.8")
G.edge("start","state2",label="0.2")
G.edge("state1","state1",label="0.5")
G.edge("state2","state2", label="0.8")
G.edge("state1","state2",label="0.5")
G.edge("state2","end",label="0.2")
G.edge("end","count",label="1.0")
G.edge("count","start",label="1.0")
G.node("start", shape="circle", color="pink")
G.render("graphs") #png/直下

graphs.png
올바르게 환경 변수가 설정되어 있지 않으면 render를 할 때 다음 오류가 발생합니다.
graphviz.backend.ExecutableNotFound: failed to execute ['dot.bat', '-Tpng', '-O', 'graphs'], make sure the Graphviz executables are on your systems' PATH
Reference
이 문제에 관하여(Anaconda 환경에서 Graphviz 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/nemutas/items/4f7bd96f63cf78bdb357
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
conda install python-graphviz
환경 변수 설정
bin까지의 경로를 환경 변수에 설정합니다.
...\Anaconda3\pkgs\graphviz-2.38-hfd603c8_2\Library\bin
※환경 변수의 추가 방법을 모르는 경우는 여기 를 참조해 주십시오.
참고: 확인을 눌러 환경 변수 화면을 제대로 닫습니다. 패스가 통과하지 않고 1 시간 정도 고민했다 
확인
DOT 명령을 사용할 수 있는지 확인
명령 프롬프트에서 다음을 수행합니다.
dot -V
// 以下が出力されればOK
dot - graphviz version 2.38.0 (20140413.2041)
DOT 언어로 확인하기
메모장 등으로 dot 파일을 만듭니다.
sample.dotdigraph g{
1 [label="x0", color=orange, style=filled]
2 [label="x1", color=orange, style=filled]
3 [label="Add", color=lightblue, style=filled, shape=box]
4 [label="y", color=orange, style=filled]
1 -> 3 [label="2"]
2 -> 3 [label="3"]
3 -> 4 [label="5"]
}
명령 프롬프트에서 다음을 수행합니다.
dot sample.dot -T png -o sample.png
sample.dot : 소스가되는 dot 파일
-T png : 렌더링할 확장자의 지정(pdf나 svg등에도 할 수 있다)
-o sample.png : 출력 파일

sample.png
Python 스크립트로 확인
test\test.pyfrom graphviz import Digraph
G = Digraph(format="png")
G.attr("node", shape="square", style="filled")
G.edge("start","state1",label="0.8")
G.edge("start","state2",label="0.2")
G.edge("state1","state1",label="0.5")
G.edge("state2","state2", label="0.8")
G.edge("state1","state2",label="0.5")
G.edge("state2","end",label="0.2")
G.edge("end","count",label="1.0")
G.edge("count","start",label="1.0")
G.node("start", shape="circle", color="pink")
G.render("graphs") #png/直下

graphs.png
올바르게 환경 변수가 설정되어 있지 않으면 render를 할 때 다음 오류가 발생합니다.
graphviz.backend.ExecutableNotFound: failed to execute ['dot.bat', '-Tpng', '-O', 'graphs'], make sure the Graphviz executables are on your systems' PATH
Reference
이 문제에 관하여(Anaconda 환경에서 Graphviz 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/nemutas/items/4f7bd96f63cf78bdb357
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
...\Anaconda3\pkgs\graphviz-2.38-hfd603c8_2\Library\bin
DOT 명령을 사용할 수 있는지 확인
명령 프롬프트에서 다음을 수행합니다.
dot -V
// 以下が出力されればOK
dot - graphviz version 2.38.0 (20140413.2041)
DOT 언어로 확인하기
메모장 등으로 dot 파일을 만듭니다.
sample.dot
digraph g{
1 [label="x0", color=orange, style=filled]
2 [label="x1", color=orange, style=filled]
3 [label="Add", color=lightblue, style=filled, shape=box]
4 [label="y", color=orange, style=filled]
1 -> 3 [label="2"]
2 -> 3 [label="3"]
3 -> 4 [label="5"]
}
명령 프롬프트에서 다음을 수행합니다.
dot sample.dot -T png -o sample.png
sample.dot : 소스가되는 dot 파일
-T png : 렌더링할 확장자의 지정(pdf나 svg등에도 할 수 있다)
-o sample.png : 출력 파일

sample.pngPython 스크립트로 확인
test\test.py
from graphviz import Digraph
G = Digraph(format="png")
G.attr("node", shape="square", style="filled")
G.edge("start","state1",label="0.8")
G.edge("start","state2",label="0.2")
G.edge("state1","state1",label="0.5")
G.edge("state2","state2", label="0.8")
G.edge("state1","state2",label="0.5")
G.edge("state2","end",label="0.2")
G.edge("end","count",label="1.0")
G.edge("count","start",label="1.0")
G.node("start", shape="circle", color="pink")
G.render("graphs") #png/直下

graphs.png올바르게 환경 변수가 설정되어 있지 않으면 render를 할 때 다음 오류가 발생합니다.
graphviz.backend.ExecutableNotFound: failed to execute ['dot.bat', '-Tpng', '-O', 'graphs'], make sure the Graphviz executables are on your systems' PATH
Reference
이 문제에 관하여(Anaconda 환경에서 Graphviz 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/nemutas/items/4f7bd96f63cf78bdb357텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)