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:
Compiled Python EXE error originating in Speedtest-cli
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
__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.
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!
Related
I did pyinstaller --onefile main.py in command prompt
This made the exe in a folder called dist where my project is which I then ran in command prompt and got the error below:
DevTools listening on ws://127.0.0.1:49451/devtools/browser/b4cedddd-0d98-4929-8fdb-b92d174992cc
[18704:11556:1103/114958.968:ERROR:device_event_log_impl.cc(214)] [11:49:58.968] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[18704:11556:1103/114958.968:ERROR:device_event_log_impl.cc(214)] [11:49:58.968] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
Traceback (most recent call last):
File "pandas\compat\_optional.py", line 138, in import_optional_dependency
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "openpyxl\__init__.py", line 6, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "openpyxl\workbook\__init__.py", line 4, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "openpyxl\workbook\workbook.py", line 9, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "openpyxl\worksheet\_write_only.py", line 13, in <module>
File "openpyxl\worksheet\_writer.py", line 23, in init openpyxl.worksheet._writer
ModuleNotFoundError: No module named 'openpyxl.cell._writer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import newspapers as np
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "newspapers.py", line 16, in <module>
from constants import driver
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "constants.py", line 9, in <module>
df = pd.read_excel('MOPI Template News & Mags.xlsx', sheet_name='Passwords')
File "pandas\util\_decorators.py", line 311, in wrapper
File "pandas\io\excel\_base.py", line 457, in read_excel
File "pandas\io\excel\_base.py", line 1419, in __init__
File "pandas\io\excel\_openpyxl.py", line 524, in __init__
File "pandas\compat\_optional.py", line 141, in import_optional_dependency
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
[2500] Failed to execute script 'main' due to unhandled exception!
I'm using python version 3.10 - i coded this program in a virtual environment where i have all the modules. When i run pip list it shows I do have openpyxl 3.0.10.
I saw a suggestion to try update the auto generated spec file and use hidden_imports variable for the modules that are missing - so I followed a video online which advised to update lines so had below added/amended:
from PyInstaller.utils.hooks import collect_submodules
hidden_imports = collect_submodules('openpyxl')
hiddenimports=hidden_imports,
I got the exact same error after trying this.
The program runs fine when in PyCharm but not when run this exe I've created. I also made sure to try run using the terminal in PyCharm too. Any ideas why I'm still getting this error?
When you open the dist folder, do you see the openpyxl module? If not, try to do it via the add-data or hidden-import. Or even easier, just copy paste it manually and see if that works. Like pyinstaller file.py --hidden-import=openpyxl
You could either try updating your pyhooks-contrib as it could have been fixed
I am working on building a GUI interface that can be ran as an executable. After using auto-py-to-exe to turn the file into an exe, I try to run it and I receive an error.
Traceback (most recent call last):
File "CarrieGUI.py", line 3, 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 495, in exec_module
File "requests.py", line 8, in <module>
AttributeError: partially initialized module 'requests' has no attribute 'get' (most likely due to a circular import)
I have seen other posts suggesting that the file name is what causes this error but I do not receive this error when running it from vscode. Plus the file name is CarrieGUI.py which should not be something referred to in the requests library. Any ideas on why I am only running into this error after converting the file to an exe?
I've recently created a program using eel, in this program I use the module moviepy to split the audio and the video of a file.
But when I try to put the whole project into an .exe file with PyInstaller, the app won't work.
The command I used is: python -m eel main.py web
I tried compiling the program without moviepy (I simply removed the import from main.py) and it perfectly worked.
So the problem is clearly moviepy which is not imported from PyInstaller.
Now I'm asking if there's any way to add moviepy dependencies using PyInstaller?
PS: Starting the source file works perfectly, it doesn't start only after compiled with PyInstaller
EDIT:
When I start the compiled .exe file with cmd, it gives me this error:
Traceback (most recent call last):
File "main.py", line 4, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\Lucad\AppData\Local\Programs\Python\Python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\moviepy\editor.py", line 84, in <module>
File "<string>", line 1, in <module>
AttributeError: module 'moviepy.audio.fx.all' has no attribute 'audio_fadein'
[8740] Failed to execute script main
EDIT 2: FOUND A SOLUTION!
I read a thread where people say that moviepy has an error importing some modules, so all I had to do was modifying a file.
This is the link of the guide I followed: https://github.com/Zulko/moviepy/issues/591
Thanks to everybody answering me!
Did you try add moviepy explicitly to the path?
pyinstaller -y -D --name Whatever --clean --distpath="." -p "c:\Python37\Lib\site-packages\moviepy" yourpyfile.pyw
I'm trying to get my feet wet with Python's asyncio module and have a simple script that runs fine but when I compile it using PyInstaller and run the executable it creates I get a runtime ImportError that I can't figure out how to fix.
I've spent several hours scouring the internet to see if anyone else has encountered the same issue but haven't been able to find anything and I don't understand what's causing the issue.
The script I'm compiling looks like this:
import requests
import asyncio
async def main():
loop = asyncio.get_event_loop()
futures = [
loop.run_in_executor(
None,
requests.get,
'http://google.com'
)
for i in range(5)
]
for response in await asyncio.gather(*futures):
print(response.status_code)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
The command I use to compile the script is:
pyinstaller -F async_test.py
And the runtime exception that is thrown when running the executable that PyInstaller creates is:
Traceback (most recent call last):
File "asyncio\__init__.py", line 18, in <module>
ImportError: cannot import name '_overlapped'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Miscellaneous\async_test.py", line 2, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\username\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "asyncio\__init__.py", line 20, in <module>
OSError: [WinError 10022] An invalid argument was supplied
[13048] Failed to execute script async_test
I'm using Python 3.6.4 and PyInstaller 3.4
If someone could shed some light on what the problem is and how to fix it I'd be very grateful.
I have installed the bloomberg Python API and set the BLPAPI_ROOT to the VC++ folder.
However, when I import blpapi, I got the following error.
How to get rid of these errors?
Thank you very much.
import blpapi
Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\blpapi\internals.py", line 39, in swig_import_helper
return importlib.import_module(mname)
File "C:\Program Files\WinPython-64bit-3.6.2.0Qt5\python-3.6.2.amd64\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
File "<frozen importlib._bootstrap>", line 560, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: DLL load failed: The specified procedure could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\blpapi\__init__.py", line 4, in <module>
from .internals import CorrelationId
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\blpapi\internals.py", line 42, in <module>
_internals = swig_import_helper()
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\blpapi\internals.py", line 41, in swig_import_helper
return importlib.import_module('_internals')
File "C:\Program Files\WinPython-64bit-3.6.2.0Qt5\python-3.6.2.amd64\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_internals'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\blpapi\__init__.py", line 9, in <module>
raise debug_load_error(error)
ImportError: No module named '_versionhelper'
Could not open the C++ SDK library.
Download and install the latest C++ SDK from:
http://www.bloomberg.com/professional/api-library
If the C++ SDK is already installed, please ensure that the path to the library
was added to PATH before entering the interpreter.
I did 2 things to solve an issue similar to that:
1- I installed Microsoft Visual Studio with the following components
C++/CLI Support
VC++ 2015.3 v14.00 (v140) toolset for desktop
Visual C++ MFC for x86 and x64
Visual C++ ATL for x86 and x64
2- I manually copied the .dll files in C++API\lib (blpapi3_32.dll and blpapi3_64.dll in my case) into C:\windows\system32 where all the dll files that system uses.
Also, I copied the dll files in in C++API\lib into C:\blp\DAPI, replacing the new ones with the old ones.
Please set BLPAPI_ROOT environment variable to the location where the blpapi C++ SDK is located.
An alternative option is to use conda, as discussed here and here.
If you use conda you don't need to worry about downloading the C++ SDK and properly configuring the BLPAPI_ROOT. From the conda-forge channel this can be done using
conda install -c conda-forge blpapi