子进程故障-Python 3.x

问题描述 投票:0回答:1

我正在尝试将.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 python-3.x subprocess
1个回答
-1
投票

在Windows上,您指定的目录是符号链接。实际路径为C:\\Users\\Jerry\\Favorites\\Desktop\\tree.dot。在Python 3.7中,this bug仍无法正确读取符号链接。您需要升级Python或更改为真实路径名。

© www.soinside.com 2019 - 2024. All rights reserved.