ydf0509 / nb_log

pip install nb_log 各种日志handler和自动转化项目的任意print的效果。日志自动彩色炫酷,可点击控制台的日志自动精确跳转到pycharm的文件和行号。文件日志多进程切割安全。在10个最重要方面全方位超过loguru
375 stars 72 forks source link

反馈一个参照了9.4后仍出现的打包bug与解决办法 #61

Open HSLix opened 9 months ago

HSLix commented 9 months ago

首先感谢大佬制作的nb_log,省了很多事,同时也促进我去学习pythonpath等知识 然后,我在用installer打包我的程序时,有按照9.4添加nb_log_config,但运行后程序有如下报错

……AttributeError: 'NoneType' object has no attribute 'write'

喂给gpt后,提示我问题出在File "nb_log\simple_print.py", line 19, in stderr_write

于是我上网找答案,在simple_print.py 19行加入以下代码解决问题,希望对其它人有用

添加stderr通道

for _name in ('stdin', 'stdout', 'stderr'): if getattr(sys, _name) is None: setattr(sys, _name, open(os.devnull, 'r' if _name == 'stdin' else 'w'))

然后也想请作者解答一下原因,比如应对这个问题还有什么更好的办法来解决 总之多谢作者的辛苦工作和无私奉献

ydf0509 commented 6 months ago

的确是,用win32serviceutil服务方式后台运行也是报错AttributeError: 'NoneType' object has no attribute 'write',

打包后运行, sys.stderr是None,None没有.write方法, 你升级下nb_log 11.6版本,我改了.