安装image_graphviz的错误解决方案

 

/**********************by garcon1986************************/

 

记录:这个问题花了我大半天的时间,半天的时间真是很痛苦,几乎已经frustrated,幸好最终还是解决了这个问题。幸好!!

好吧,这个是我stackoverflow上发的帖子。

全程描述:

第一步:安装pear。

第二步:利用pear命令安装image_graphviz。目前安装的是image_graphviz-1.2.1版本(stable release)。 命令有: cmd -> pear install image_graphviz  。

第三步:安装Graphviz。必须是Graphviz.msi。不能是development snapshot里的msi或者zip文件。

第四步:在安装好的C:/wamp/bin/php/php5.3.0/PEAR/Image路径下的Graphviz.php中进行如下修改。(image_graphviz-1.2.1版本,第104行开始)

 

/**
* Path to GraphViz/dot command
*
* @var  string
*/
var $dotCommand = 'C://Graphviz2.24//bin//dot';   //安装路径

/**
* Path to GraphViz/neato command
*
* @var  string
*/
var $neatoCommand = 'C://Graphviz2.24//bin//neato';  //安装路径

第五步:test.php页面调用画出图表。

<?php
require_once 'Image/GraphViz.php';
error_reporting(E_ALL ^ E_NOTICE);
$gv = new Image_GraphViz();
$gv->addEdge(array('wake up'        => 'visit bathroom'));
$gv->addEdge(array('visit bathroom' => 'make coffee'));
$gv->image();
?>

 

在pear php官网上也有帖子的解决方案。我就是按照他的方法解决的。

http://pear.php.net/bugs/bug.php?id=3349&edit=1

 

发问:

Hello,

I have got a warning in image_graphviz, i have viewed a post , who has a similar error. I have installed pear image_graphviz package(Image_GraphViz-1.2.1 ), I also installed graphviz.msi(Graphviz2.25.msi ) in windows(But i don't know if does something with image_graphviz and if it does have some effects when i use image_graphviz).

Do i need to do something else?

Here is my code from pear image_graphviz site.

<?php
require_once 'Image/GraphViz.php';
error_reporting(E_ALL ^ E_NOTICE); //Added E_NOTICE
$gv = new Image_GraphViz();
$gv->addEdge(array('wake up' => 'visit bathroom'));
$gv->addEdge(array('visit bathroom' => 'make coffee'));
$gv->image();
?>

This is the warning:
Warning: fopen(C:/WINDOWS/Temp/gra50.tmp.svg) [function.fopen]: failed to open stream: No such file or directory in C:/wamp/bin/php/php5.3.0/PEAR/Image/GraphViz.php on line 210

Notice: Undefined variable: data in C:/wamp/bin/php/php5.3.0/PEAR/Image/GraphViz.php on line 



Thanks Pekka Gaiser, I used error_reporting(E_ALL ^ E_NOTICE); . I don't know how to change the temp directory, but c:/windows/temp exists in my computer.

I haven't solve the problem. Thanks all for advice.

 

回答:

[Edited] Are you sure your Graphviz pear package can actually call the binary you installed? Does the package have any settings, maybe (probably) you have to specify the path there?

If the binary is definitely there: Does the c:/windows/temp directory exist? Can you change the temporary directory somewhere in Graphviz? Are you really on Windows? Can you change the location of the temporary setting in php.ini?

To address the notice, try setting error_reporting to error_reporting(E_ALL ^ E_NOTICE)

Notices about undefined variables give important guidance at development time, but if they occur in a production package the only way to get rid of them is to turn them off.

Reply:

Thanks Pekka Gaiser, i have checked the file Image/Graphviz.php and it doesn't indicate any directory about temp. The c:/windows/temp does exists and i don't know how to change it. I think it's default by windows system, not by graphviz. I don't find the settings in php.ini too. But i use E_NOTICE because of your advice. The Notice line is disappeared. But i still have the warning. Thanks.

Reply:

Then you need to check whether the Graphviz PEAR package knows about the Graphviz Program you installed. There is most likely a settings file somewhere where you can set the path. However I don't know this for sure as I know neither PEAR nor Graphviz. – Pekka Gaiser

Reply:

I have solved it. Because the path is not right. Thanks pek.

graph relations {
 {rank=min; Emil}
        Emil -- Elias;
        Emil -- Linda;
        Elias -- Annelie;
        Elias -- Mamma;
        Annelie -- Mamma;
        Linda -- Mamma;
        Linda -- Annelie;
        Mamma -- Stefan;
        Stefan -- Elias;
        Emil -- Patrik;
        Patrik -- Elias;
        Emil -- Karin;
        Emil -- Per;
        Per -- Lars;
        Emil -- Greta;
        Per -- Greta;
        Greta -- Lars;
} 我的另外一个帖子:
http://stackoverflow.com/questions/1998671/how-to-draw-social-networking-graph

I run this command: dot -Tpng emil.dot -o emil.png

I get this file:
Graph over Emil's relations

If I instead run this command, which is also part of Graphviz: circo -Tpng emil.dot -o emil2.png

, I get this file:
Another graph over Emil's relations

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
export_graphviz是一个函数,用于将决策树可视化。它可以将决策树以.dot文件的格式保存下来,然后可以使用graphviz库将该文件转换为可视化的图形。在使用export_graphviz函数时,需要提供以下参数: - 第一个参数是已经训练好的决策树模型。 - out_file参数用于指定保存.dot文件的路径和文件名。 - feature_names参数是一个列表,用于指定每个特征的名称。 - impurity参数用于确定是否在每个节点上显示不纯度信息。 - filled参数用于确定是否给每个节点上色,以表示多数类别。 例如,可以使用以下代码将决策树保存为.dot文件: ``` from sklearn.tree import export_graphviz # 假设已经训练好了决策树模型classifier,并且有一个特征名称列表feature_names tree_dot = export_graphviz(classifier, out_file='tree.dot', feature_names=feature_names, impurity=False, filled=True) ``` 注意,在运行export_graphviz函数之前,需要确保已经正确导入了sklearn.tree模块。此外,如果报错提示"dot.exe not found in path",可能是因为没有正确安装graphviz或者没有将graphviz安装路径添加到系统环境变量中。可以尝试重新安装graphviz并添加到环境变量中,或者将graphviz安装路径手动添加到Python项目的环境变量中。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [决策树算法之讲解实操(下)](https://blog.csdn.net/weixin_43580339/article/details/115939923)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [解决使用export_graphviz可视化树报错的问题](https://download.csdn.net/download/weixin_38506103/13998100)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值