'Pyinstaller speedtest convert to exe error; no module name "__builtin__"
I am trying to convert a program to an exe using pyinstaller. The program performs a hardware assessment of a user's computer to include running an internet speed test utilizing speedtest-cli. The program runs fine until I compile it at which point I receive the following error:
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'
I have tried upgrading and re-installing speedtest-cli and it has not corrected the issue.
P.S. Here is a screenshot of the error:
Solution 1:[1]
__builtin__
was changed to builtins
in Python 3. I pulled the speedtest-cli code from the repo and edited out the Python2 functionality and it worked fine.
Solution 2:[2]
I met same issue before, you need to modify the spec file: hiddenimports=['speedtest'], and build exe via spec file(type command: pyinstaller -F main.spec), It's work!
Solution 3:[3]
First you need to go to C:\Users\user\AppData\Local\Programs\Python\Python38\Lib\site-packages. Then find the speedtest.py and open it with Notepad or any other Text Editor.
Now you need to edit these lines of code
Line 156: to
import builtins
Line 158 : to
import builtins
Line 199: to
del builtins
To confirm, you can find for __builtin__
and replace it with builtins
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Russ C |
Solution 2 | Ervin |
Solution 3 | Dasun Nethsara |