将 py 转换为 exe 文件时脚本错误中未处理的异常

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

我在通过 pyinstaller 将 py 文件转换为 exe 文件时遇到问题,因为出现以下错误

unhandled exception in script.
Failed to execute script 'main' due to unhandled exception: None type object has no attribute 'write'
Traceback (most recent call last):
  File "main.py", line 5, in <module>
  File "pip\__init__.py", line 13, in main
  File "pip\_internal\utils\entrypoints.py", line 35, in _wrapper
AttributeError: 'NoneType' object has no attribute 'write'

enter image description here

exception pyinstaller attributeerror unhandled
1个回答
0
投票

您提供的错误消息表明您尝试使用 PyInstaller 执行的“主”脚本存在问题。看起来错误是在 PyInstaller 尝试执行脚本的依赖项时发生的,特别是“pip”模块。

此问题的一个可能解决方案是尝试升级您的 PyInstaller 版本,因为较新的版本可能已经解决了此问题。您可以通过在终端中运行以下命令来执行此操作:

CSS 复制代码 pip install --upgrade pyinstaller 如果升级 PyInstaller 不能解决问题,您可能需要进一步调查以确定错误的根本原因。一种方法是尝试在不使用 PyInstaller 的情况下运行脚本,以查看错误是否仍然存在。这可以帮助您确定问题是出在您的脚本上还是出在 PyInstaller 本身上。

另一种方法是检查您的脚本是否有任何对 None 类型对象上的“write”方法的引用。此错误消息表明这是导致错误的具体问题。如果你在你的脚本中发现这个问题,你可以通过在调用 write 方法之前确保被引用的对象不是 None 来解决它。

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