使用Python库Winotify创建通知时遇FileNotFoundError错误求助
Winotify创建Toast通知出现FileNotFoundError的解决办法
问题重现
使用Winotify库创建Windows Toast通知时,执行测试脚本后触发FileNotFoundError。测试脚本如下:
from winotify import Notification toast = Notification(app_id="windows app", title="Winotify Test Toast", msg="New Notification!") toast.show()
错误信息
运行脚本后抛出以下错误:
Traceback (most recent call last): File "D:\01 Libraries\Documents\Tosh0kan Studios\Coding\MangaDex Feed Notifier\_toaster.pyw", line 8, in <module> toast.show() File "C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\site-packages\winotify\__init__.py", line 197, in show _run_ps(command=self.script) File "C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\site-packages\winotify\__init__.py", line 72, in _run_ps subprocess.Popen( File "C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1022, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1491, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [WinError 2] The system cannot find the file specified
排查与解决
已尝试以下操作但未解决问题:
- 卸载并重新安装Winotify库
- 切换至Python 3.9版本
最终定位问题根源:PowerShell未添加至系统PATH环境变量中。将PowerShell的路径(通常为C:\Windows\System32\WindowsPowerShell\v1.0)添加到系统PATH后,重新运行脚本即可正常显示Toast通知。
内容的提问来源于stack exchange,提问作者DorderaDomo
相关产品推荐
相关产品推荐

