使用graph.write_png() 时出现 "dot.exe" not found in path 和 [Errno 13] Permission denied: 'somefile.png'

## 使用graph.write_png()出错 ##

最近在学习机器学习里面的决策树,看完理论了之后在网上找了鸢尾花的决策树实例来实现,但是到了最后一步graph.write_png(r"D:\python的学习笔记\somefile.png")的时候出现 "dot.exe" not found in path,查了之后发现是之前安装pydot和Graphviz时没有将Graphviz2.38添加到环境变量中,添加环境变量的代码如下:


import pydot

import os
os.environ['PATH'] = os.environ['PATH'] + (';D:\\Python\\Scripts\\graphviz-2.38\\release\\bin\\')

但是弄好环境变量之后用的代码是graph.write_png("somefile.png")
所以又出现[Errno 13] Permission denied: 'somefile.png' 这样的报错,所以我把代码改成了graph.write_png(r"D:\python的学习笔记\somefile.png") 就成功啦~~~~

希望能帮助到和我遇见同样问题的同学~~~


我再把我再网上找的鸢尾花的决策树demo附上吧…

<
(venv) D:\qsy\frontend>npm install --unsafe -perm npm warn tar TAR_ENTRY_ERROR ENOENT: no such file or directory, open 'D:\qsy\frontend\node_modules\asynckit\LICENSE' npm warn tar TAR_ENTRY_ERROR ENOENT: no such file or directory, open 'D:\qsy\frontend\node_modules\asynckit\bench.js' npm warn tar TAR_ENTRY_ERROR ENOENT: no such file or directory, open 'D:\qsy\frontend\node_modules\asynckit\index.js' npm warn tar TAR_ENTRY_ERROR ENOENT: no such file or directory, open 'D:\qsy\frontend\node_modules\asynckit\stream.js' npm warn tar TAR_ENTRY_ERROR ENOENT: no such file or directory, open 'D:\qsy\frontend\node_modules\asynckit\parallel.js' npm warn tar TAR_ENTRY_ERROR ENOENT: no such file or directory, open 'D:\qsy\frontend\node_modules\asynckit\serial.js' npm warn tar TAR_ENTRY_ERROR ENOENT: no such file or directory, open 'D:\qsy\frontend\node_modules\asynckit\serialOrdered.js' npm warn cleanup Failed to remove some directories [ npm warn cleanup [ npm warn cleanup '\\\\?\\D:\\qsy\\frontend\\node_modules\\axios', npm warn cleanup [Error: ENOTEMPTY: directory not empty, rmdir 'D:\qsy\frontend\node_modules\axios\lib\core'] { npm warn cleanup errno: -4051, npm warn cleanup code: 'ENOTEMPTY', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'D:\\qsy\\frontend\\node_modules\\axios\\lib\\core' npm warn cleanup } npm warn cleanup ], npm warn cleanup [ npm warn cleanup 'D:\\qsy\\frontend\\node_modules\\axios', npm warn cleanup [Error: ENOTEMPTY: directory not empty, rmdir 'D:\qsy\frontend\node_modules\axios\lib\core'] { npm warn cleanup errno: -4051, npm warn cleanup code: 'ENOTEMPTY', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'D:\\qsy\\frontend\\node_modules\\axios\\lib\\core' npm warn cleanup } npm warn cleanup ], npm warn cleanup [ npm warn cleanup '\\\\?\\D:\\qsy\\frontend\\node_modules\\@babel\\types', npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'D:\qsy\frontend\node_modules\@babel\types\lib\asserts\generated'] { npm warn cleanup errno: -4048, npm warn cleanup code: 'EPERM', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'D:\\qsy\\frontend\\node_modules\\@babel\\types\\lib\\asserts\\generated' npm warn cleanup } npm warn cleanup ], npm warn cleanup [ npm warn cleanup 'D:\\qsy\\frontend\\node_modules\\entities', npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'D:\qsy\frontend\node_modules\entities\lib\esm'] { npm warn cleanup errno: -4048, npm warn cleanup code: 'EPERM', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'D:\\qsy\\frontend\\node_modules\\entities\\lib\\esm' npm warn cleanup } npm warn cleanup ] npm warn cleanup ] npm warn tar TAR_ENTRY_ERROR ENOENT: no such file or directory, lstat 'D:\qsy\frontend\node_modules\asynckit\lib' npm warn tar TAR_ENTRY_ERROR ENOENT: no such file or directory, lstat 'D:\qsy\frontend\node_modules\asynckit\lib' npm error code EPERM npm error syscall mkdir npm error path C:\Program Files\nodejs\node_cache npm error errno -4048 npm error Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache' npm error at async Object.mkdir (node:internal/fs/promises:852:10) npm error at async makeTmp (C:\Program Files\nodejs\node_modules\npm\node_modules\cacache\lib\content\write.js:156:3) npm error at async handleContent (C:\Program Files\nodejs\node_modules\npm\node_modules\cacache\lib\content\write.js:103:15) { npm error errno: -4048, npm error code: 'EPERM', npm error syscall: 'mkdir', npm error path: 'C:\\Program Files\\nodejs\\node_cache' npm error } npm error npm error The operation was rejected by your operating system. npm error It's possible that the file was already in use (by a text editor or antivirus), npm error or that you lack permissions to access it. npm error npm error If you believe this might be a permissions issue, please double-check the npm error permissions of the file and its containing directories, or try running npm error the command again as root/Administrator. npm notice npm notice New major version of npm available! 10.9.2 -> 11.4.2 npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.4.2 npm notice To update run: npm install -g npm@11.4.2 npm notice npm error Log files were not written due to an error writing to the directory: C:\Program Files\nodejs\node_cache\_logs npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal 报错,npm无法安装,帮我解决问题
06-22
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值