본문 바로가기
ERROR

InvocationException: Program terminated with status: 1. stderr follows: Format: "png" not recognized. Use one of:

by sooyeoon 2022. 4. 16.

발생 오류

실행한 코드

graph.write_png('tree.png')  # 결정 트리를 위한 그림 저장

결과

InvocationException: Program terminated with status: 1. stderr follows: Format: "png" not recognized. Use one of:

 

결정 트리를 생성하고 graphvis를 이용해 결과를 이미지 (png) 형식으로 저장하는 과정에서 발생한 에러

 

 

오류 해결

anaconda cmd를 관리자 권한으로 실행 >  dot -c 입력 >

에러가 발생한 코드 다시 실행 > True

주피터 노트북을 실행한 경로로 들어가보면 해당 이미지 파일이 저장된 것을 확인할 수 있다.

breast cancer datasets decision tree graph

matplotlib으로 해당 image 파일을 불러옴

# import
import matplotlib.pyplot as plt
import matplotlib.image as img

# imshow
t_image = img.imread('tree.png')
plt.figure(figsize=(15,15))
plt.imshow(t_image)
plt.show()

참고 링크 :  https://chowdera.com/2021/10/20211017134540590m.html

 

Program terminated with status: 1. stderr follows: Format: “png“ not recognized. Use one of:

Error reporting when drawing visual image of decision tree Content InvocationException Traceback (most recent call last) in () 9 filled=True, rounded=True, special_characters=True) 10 graph = pydotplus.graph_from_dot_data(dot_tree) —> 11 img2 = Image(gra

chowdera.com

 

+) 크기 조정 없이 graphviz에서 바로 불러오기 

from sklearn.tree import export_graphviz
export_graphviz(tree1, out_file="tree.dot", class_names=["malignant", "benign"],
                feature_names=cancer.feature_names, impurity=False, filled=True)
import graphviz

with open("tree.dot") as f:
    dot_graph = f.read()
display(graphviz.Source(dot_graph))