【问题标题】:Pyinstaller speedtest convert to exe error; no module name "__builtin__"Pyinstaller speedtest 转换为 exe 错误;没有模块名称“__builtin__”
【发布时间】:2021-11-18 02:19:12
【问题描述】:

我正在尝试使用 pyinstaller 将程序转换为 exe。该程序执行用户计算机的硬件评估,包括使用 speedtest-cli 运行互联网速度测试。该程序运行良好,直到我编译它,此时我收到以下错误:

Traceback (most recent call last):   File "speedtest.py", line 156, in <module> ModuleNotFoundError: No module named '__builtin__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "hw-assesment-tool.py", line 9, in <module>   File "<frozen importlib._bootstrap>", line 1007, in
_find_and_load   File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked   File "<frozen importlib._bootstrap>", line 680, in _load_unlocked   File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module   File "speedtest.py", line 179, in <module>   File "speedtest.py", line 166, in __init__ AttributeError: 'NullWriter' object has no attribute 'fileno'

我已尝试升级并重新安装 speedtest-cli,但仍未解决问题。

附:这是错误的屏幕截图:

Compiled Python EXE error originating in Speedtest-cli

【问题讨论】:

    标签: python runtime-error pyinstaller speed-test


    【解决方案1】:

    __builtin__ 在 Python 3 中更改为 builtins。我从 repo 中提取了 speedtest-cli 代码并编辑了 Python2 功能,它运行良好。

    【讨论】:

      【解决方案2】:

      我之前遇到过同样的问题,你需要修改spec文件:hiddenimports=['speedtest'],并通过spec文件构建exe(输入命令:pyinstaller -F main.spec),它的工作!

      【讨论】:

        【解决方案3】:

        首先您需要转到 C:\Users\user\AppData\Local\Programs\Python\Python38\Lib\site-packages。然后找到 speedtest.py 并使用记事本或任何其他文本编辑器打开它。

        现在你需要编辑这些代码行

        第 156 行:到

        import builtins
        

        第 158 行:到

        import builtins
        

        第 199 行:到

        del builtins
        

        要确认,您可以找到__builtin__并将其替换为builtins

        【讨论】:

          猜你喜欢
          • 2021-03-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-05-19
          • 2017-11-28
          • 2021-07-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多