[python] Graphviz error_No such file or directory 'dot' 해결

2023. 1. 18. 23:00Programming

728x90

1. 현상

파이썬 코드를 돌리다가 에러 메시지를 확인하면, 아래와 같이 해결한다.

FileNotFoundError: [Error 2] No such file or directory: 'dot': 'dot'

경로가 잘못 설정되었는지 코드를 엄청 살폈는데, 원인은 다른 곳에 있었다.

tree.export_graphviz(decision_tree,
		out_file=f,
		max_depth = 4,
		impurity = False,
		feature_names = train.drop(['id', 'target'],axis=1).columns.values,
		class_names = ['No', 'Yes'],
		rounded = True,
		filled= True )

 

728x90

 

2. 해결방법

tree.export_graphviz를 실행할 때는 이슈가 없는 것처럼 작동해서 몰랐는데, Graphviz가 설치되지 않아서 위의 에러가 발생했다.

sudo apt install python-pydot python-pydot-ng graphviz

이렇게 graphviz를 설치해주고 다시 실행해주면 된다.

 

3. 결과

문제없이 코드가 잘 실행된다.

(에러 메시지가 친절하지 않아서.. 분석환경 새로 만들면 또 정신 못 차릴 것 같다..)

 

 

 

반응형