子进程失败 - Python 3.x

2024-09-24 22:23:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将.dot文件(决策树可视化的输出)转换为.jpg文件。代码如下:

estimator = rf.estimators_[5]

export_graphviz(estimator, 
                out_file='C:\\Users\\Jerry\\Desktop\\tree.dot', 
                feature_names = ['count_bot', 'count_human', '%_bot_tweets',  'following',  'followers'],
                class_names = ['bot', 'human'],
                rounded = True, proportion = False, 
                precision = 2, filled = True)
call(['dot', '-Tpng', 'C:\\Users\\Jerry\\Desktop\\tree.dot', '-o', 'C:\\Users\\Jerry\\Desktop\\tree.png', '-Gdpi=600']) 

它产生:

Traceback (most recent call last):
  File "filepath\Bot_or_Not.py", line 89, in <module>
    call(['dot', '-Tpng', 'C:\\Users\\Jerry\\Desktop\\tree.dot', '-o', 'C:\\Users\\Jerry\\Desktop\\tree.png', '-Gdpi=600'])
  File "C:\Users\Jerry\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 304, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Users\Jerry\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Jerry\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1155, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

I am trying to follow this tutorial.

我的台词有什么问题:call(['dot', '-Tpng', 'C:\\Users\\Jerry\\Desktop\\tree.dot', '-o', 'C:\\Users\\Jerry\\Desktop\\tree.png', '-Gdpi=600'])

顺便说一下,我可以确认tree.dot在我的桌面上

回复评论:

我运行的命令是: python Bot_or_Not.py

脚本的其余部分(实际上构建/训练/测试分类器)运行得很好

python --version产生:

Python 3.7.0

python -m pip install Graphviz产生:

C:\Users\Jerry>python -m pip install Graphviz Requirement already satisfied: Graphviz in c:\users\Jerry\appdata\local\programs\python\python37\lib\site-packages (0.13.2)


Tags: inpytreepnglibbotlinecall