Problems with Converting a .py to .exe - python

I am trying to convert a .py to a .exe with auto-py-to-exe.
I get this error when i run the .exe
Traceback (most recent call last):
File "main.py", line 4, 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 540, in exec_module
File "random_word\__init__.py", line 1, 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 540, in exec_module
File "random_word\random_word.py", line 20, in <module>
File "random_word\utils\utils.py", line 28, in get_api_keys
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\phili\\AppData\\Local\\Temp\\_MEI162522\\random_word\\config.yml'
[15844] Failed to execute script main

Since the error you are getting is FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\phili\\AppData\\Local\\Temp\\_MEI162522\\random_word\\config.yml' I am assuming that inside of your python script you hardcoded the filepath to config.yml. Once you compile your python script and move it to a different directory, the script will not be able to find the file anymore and yield the FileNotFoundError.
To fix the issue you can either provide a command line flag that provides the filepath to config.yml or you can embedd the file into your python script as described in this post.

Fixed by using another way to generate random words.

Related

Error in geopandas module while running binary application of python script in linux

When I run python script it is working fine but when tried to run executable of same python script made using pyinstaller then getting module error. Specifically getting error while importing geopanda module. The error coming is mentioned below:
ERROR 1: PROJ: proj_create_from_database: Cannot find proj.db
PROJ: proj_create_from_database: Cannot find proj.db
Traceback (most recent call last):
File "ImageChecker.py", line 27, 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 "geopandas/__init__.py", line 17, 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 "geopandas/datasets/__init__.py", line 6, in <module>
StopIteration
[7062] Failed to execute script 'ImageChecker' due to unhandled exception!

Python Standalone Executable file does not run and shows error in Command Prompt

As I am new in Python, I made a VOICE ASSISTANT by Python in Pycharm. I only write the code and run I in the pycharm, it ran smoothly. I haven't made any GUI for it. I just converted the code in the EXE file by using the Pyinstaller. when I run the exe file, it has shown me this error in Command Prompt.
Traceback (most recent call last):
File "site-packages\pyttsx3\__init__.py", line 20, in init
File "c:\users\faizan\appdata\local\programs\python\python36\lib\weakref.py", line 131, in
__getitem__
o = self.data[key]()
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "s.py", line 15, in <module>
File "site-packages\pyttsx3\__init__.py", line 22, in init
File "site-packages\pyttsx3\engine.py", line 30, in __init__
File "site-packages\pyttsx3\driver.py", line 50, in __init__
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pyttsx3.drivers'
[2844] Failed to execute script s
I think, this the problem of many beginners. Please Help.
Use hidden import to specify the module while creating exe,
$ pyinstaller --hidden-import=pyttsx3.drivers yourscript.py

"Failed to load dynlib/dll" While executing the "*.exe " file after binding it with PyInstaller

The code successfully works while executing using CMD , but when it is binded to *.exe file using Pyinstaller, It throws an error and stops executing (the Message is given below). I tried all possible solutions by linking the path library and other stuff too.
MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
exec(bytecode, module.__dict__)
Traceback (most recent call last):
File "site-packages\pyinstaller-4.0.dev0-py3.7.egg\PyInstaller\loader\pyiboot01_bootstrap.py", line 167, in __init__
File "ctypes\__init__.py", line 364, in __init__
OSError: [WinError 126] The specified module could not be found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "try.py", line 2, 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\Mohammed Hashim\AppData\Local\Programs\Python\Python37\lib\site-packages\pyinstaller-4.0.dev0-py3.7.egg\PyInstaller\loader\pyimod03_importers.py", line 489, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sklearn\__init__.py", line 80, 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\Mohammed Hashim\AppData\Local\Programs\Python\Python37\lib\site-packages\pyinstaller-4.0.dev0-py3.7.egg\PyInstaller\loader\pyimod03_importers.py", line 489, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sklearn\_distributor_init.py", line 18, in <module>
File "site-packages\pyinstaller-4.0.dev0-py3.7.egg\PyInstaller\loader\pyiboot01_bootstrap.py", line 169, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll 'C:\\Users\\MOHAMM~1\\AppData\\Local\\Temp\\_MEI38242\\sklearn\\.libs\\vcomp140.dll'. Most probably this dynlib/dll was not found when the application was frozen.
[13968] Failed to execute script try
Previously , It was [11496] Failed to execute script try with similar error message.
I also hereby share my code. (this code was written to check the missing library and Error Message - Handy error detection)
import pandas as pd
from sklearn import datasets
data = pd.read_csv(r"D:\PROGRAMS\DATASETS\Kang_nose_data_csv.csv")
print(data.head())
It produces similar error for sklearn,numpy and pandas and many other libraries.
Thanks...!

Missing dill was found using pyinstaller to compile executable file

I built a small program using sklearn, numpy and pandas, I tried to compile the file but it failed and have the following error message, it said there was a missing dll file in some location. I looked at this thread.
File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 174, in __init__
File "ctypes\__init__.py", line 373, in __init__
FileNotFoundError: Could not find module 'C:\Users\Dennis\AppData\Local\Temp\_MEI101722\sklearn\.libs\vcomp140.dll' (or one of its dependencies). Try using the full path with constructor syntax.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "sklearn111.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "c:\users\dennis\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sklearn\__init__.py", line 78, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "c:\users\dennis\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sklearn\_distributor_init.py", line 18, in <module>
File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 176, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll 'C:\\Users\\Dennis\\AppData\\Local\\Temp\\_MEI101722\\sklearn\\.libs\\vcomp140.dll'. Most probably this dynlib/dll was not found when the application was frozen.
[6572] Failed to execute script gui_plus_model
So I put the dll it needs at the same folder with the .py file to be compiled, but the same error exist. The version of python is 3.8 and all modules needed have already been upgraded to the latest version.
pyinstaller -F --add-binary "vcomp140.dll;.dll" gui_plus_model.py

How to add lib_lightgbm.dll to exe when using pyinstaller to freeze python code

I am creating a single-file executable of a python code that imports Microsoft's LightGBM. I used the following command to create the exe:
pyinstaller -F --hidden-import numpy.core._dtype_ctypes pro.py
After creating the exe and running it, the following error occurs:
Exception: Cannot find lightgbm library file in following paths:
C:\Users\...\AppData\Local\Temp\_MEI61682\lightgbm\lib_lightgbm.dll
C:\Users\...\AppData\Local\Temp\lib_lightgbm.dll
C:\Users\...\AppData\Local\Temp\_MEI61682\lightgbm\compile\lib_lightgbm.dll
C:\Users\...\AppData\Local\Temp\_MEI61682\compile\lib_lightgbm.dll
C:\Users\...\AppData\Local\Temp\lib\lib_lightgbm.dll
C:\Users\...\AppData\Local\Temp\_MEI61682\compile\Release\lib_lightgbm.dll
C:\Users\...\AppData\Local\Temp\_MEI61682\compile\windows\x64\DLL\lib_lightgbm.dll
C:\Users\...\AppData\Local\Temp\Release\lib_lightgbm.dll
C:\Users\...\AppData\Local\Temp\windows\x64\DLL\lib_lightgbm.dll
[6352] Failed to execute script pro
I tried adding lib_lightgbm.dll using the option :
--add-data lib_lightgbm.dll;\compile
This resolves the error on the machine that lightgbm is installed, but on other machines, it gives the following error:
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 149, in __init__
File "ctypes\__init__.py", line 348, in __init__
OSError: [WinError 126] The specified module could not be found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pro.py", line 9, 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\...\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "site-packages\lightgbm\__init__.py", line 8, 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\...\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "site-packages\lightgbm\basic.py", line 34, in <module>
File "site-packages\lightgbm\basic.py", line 29, in _load_lib
File "ctypes\__init__.py", line 426, in LoadLibrary
File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 151, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll 'C:\\Users\\...\\AppData\\Local\\Temp\\_MEI7562\\lightgbm\\../compile\\lib_lightgbm.dll'. Most probably this dynlib/dll was not found when the application was frozen.
[4060] Failed to execute script pro
Can anyone help me resolve this issue?

Categories