Error when creating executable file with pyinstaller - python

I'm trying to create an exe for my python script using pyinstaller each time it runs into errors which can be found in a pastebin here.
Also when I double click the exe file it shows this error:
C:Users\Afro\AppData\Local\Temp_MEI51322\VCRUNTIME140.dll is either not designed to run on windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support. Error status 0xc000007b
and then this:
Error loading Python DLL:
C:\Users\Afro\AppData\Local\Temp_MEI51322\python35.dll(error code 193)
what's wrong, please?

I was haunted with similar issue. It might be that in your case UPX is breaking vcruntime140.dll.
Solution to this is turning off UPX, so just add --noupx to your pyinstaller call.
pyinstaller --noupx --onedir --onefile --windowed get.py
Long explanation here: UPX breaking vcruntime140.dll (64bit)

I have also met this issue, and the root cause is that I am using upx to compress the file size. The solution is to exclude files which should not be compressed by upx:
pyinstaller --onefile --console --upx-dir=/path/to/upx --upx-exclude=vcruntime140.dll --upx-exclude=python36.dll my_script.py

In my case it was:
pyinstaller --clean --win-private-assemblies --noupx --onedir --onefile script.py
--windowed caused problems with wxWidgets

I tried with this version of Pyinstaller commands, Add this commands to a .bat file and execute the .bat file. It worked for me:
pyinstaller --log-level=WARN ^
--upx-dir <PATH_TO_UPX.exe_FILE> ^
--upx-exclude vcruntime140.dll ^
--upx-exclude ucrtbase.dll ^
--upx-exclude qwindows.dll ^
--upx-exclude libegl.dll ^
--name <NAME_OF_APPLICATION> ^
--onefile --windowed ^
<PY_DEPENDENT_FILES.py>

Related

.exe file made by pyinstaller pops up DLL error. tkinter is crashing

I have made simple application with tkinter and json libraries. The complexity is quiet big because there are few classes in separated .py files which are "tree-like connected". The script itself works perfectly but once I use pyinstaller to make it into .exe file this error occurs.
Execute error:
Line 8 Erro:
I am using 2 pictures, one as background and second one as a frame picture, 1 label and 1 textbox. Even when I manually add images folder into dist folder it does not help.
Build command is as follows:
venv\Scripts\pyinstaller.exe Editor.py --distpath ./Ready_For_Testing --workpath ./temp_build --specpath ./spec_build -w --hidden-import tkinter
Well I have just solved this issue even so it is manual solving.
If you use virtual enviroment you should go in your enviroment for example mine: D:\GitHub\SnA-KPIS-JSON-Editor\20_Implementation\venv
If you use system/allFor Python go inside your Python, path could look like this : C:\Users\YourLogin\Programs\PythonX.X
Inside in the Python folder copy folder named Library and just paste it inside your folder with .exe file. File you built with pyinstaller.
Feel free to remove any other folders inside Library but bin, that must stay. It's key to solve the issue.
If you have images which are used in tkinter you have to copy and paste them inside your build folder as well.
It's simple and easily done. Hope this will help some others who will face the same issue.
EDIT: I found out that there is a way to solve this by adding more options inside your pyinstaller command.
Command:
pyinstaller.exe Editor.py --distpath ./Ready_For_Testing --workpath ./temp_build --specpath ./spec_build --paths D:\GitHub\SnA-KPIS-JSON-Editor\20_Implementation\venv\Library\bin --hidden-import tkinter --hidden-import tkinter.filedialog --collect-all tkinter --windowed --hidden-import tkinter.messagebox
Main thing in the command is that you have to detect missing libraries/dlls which you can find inside stdout while "installing" .exe file.
Here is exact Warning output which you should look for in case of similar or same problem:
674 WARNING: lib not found: liblzma.dll dependency of D:\GitHub\SnA-KPIS-JSON-Editor\20_Implementation\venv\DLLs\_lzma.pyd
690 WARNING: lib not found: LIBBZ2.dll dependency of D:\GitHub\SnA-KPIS-JSON-Editor\20_Implementation\venv\DLLs\_bz2.pyd
721 WARNING: lib not found: ffi.dll dependency of D:\GitHub\SnA-KPIS-JSON-Editor\20_Implementation\venv\DLLs\_ctypes.pyd
737 WARNING: lib not found: tk86t.dll dependency of D:\GitHub\SnA-KPIS-JSON-Editor\20_Implementation\venv\DLLs\_tkinter.pyd
737 WARNING: lib not found: tcl86t.dll dependency of D:\GitHub\SnA-KPIS-JSON-Editor\20_Implementation\venv\DLLs\_tkinter.pyd
When you take a look inside Library\bin folder inside enviroment there you can see these missing files. And that is why you have to add them in --paths option.
Missing dlls

PyAutoit : OSError: Cannot load AutoItX from path: C:\Users\User\AppData\Local\Temp\_MEI152482\autoit\lib\AutoItX3_x64.dll

I been trying to compile this program for quite some time but can't seem to figure out what is going on. From just reading the error code I'm assuming pyinstaller cannot or does not know where the needed AutoitX3_64.dll file. I've read other questions but cant seem to find a detailed answer explain how to tell my installer where the files are located.
I've tried:
pyinstaller --onefile main.py (Fail)
pyinstaller -w --onefile --add-data C:\Users\User\AppData\Local\Programs\Python\Python310\Lib\site-packages\autoit\lib\AutoItX3_x64.dll;autoit\lib main.py (Fail)
I've also dumped autoit folder in my build / dist with no success.
Any help would be greatly apriciated!
[error1][error2]
After searching this site and countless others i managed to figure out how to fix the error:
OSError: Cannot load AutoItX from path:
C:\Users\myusername\AppData\Local\Temp\_MEI152482\autoit\lib\AutoItX3_x64.dll
The answer would be to make a spec file and tell it where the autoit files are located. Here is how!
When you run pyinstaller command it will automatically generate a filename.spec in your home dir. For example:
pyinstaller -w --onefile main.py
-w is no console --onefile is to compress all files into one executable. main.py is the file you are going to make into exe. Now you will see a filename.spec in your home dir. Edit that with the following datas and hiddenimports
datas=
[["C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310\\Lib\\site-packages\\autoit\\lib\\AutoItX3_x64.dll", "autoit\\lib"]],
hiddenimports=["autoit.init", "autoit.autoit", "autoit.control", "autoit.process", "autoit.win" ],
Here is an example and don't forget to copy and paste the autoit\lib into your dist folder.

FileNotFoundError Selenium Stealth Python

I am running selenium-stealth in Python 3.9.3 on MacOS.
When I build to an app using PyInstaller (
pyinstaller --noconfirm --onefile --console --hidden-import "cmath" "/Users/name/Downloads/AmazonSellerCentral/main.py") I get the following error:
Traceback (most recent call last):
File "main.py", line 141, in <module>
File "main.py", line 77, in create_driver
File "selenium_stealth/__init__.py", line 45, in stealth
File "selenium_stealth/utils.py", line 8, in with_utils
File "pathlib.py", line 1255, in read_text
File "pathlib.py", line 1241, in open
File "pathlib.py", line 1109, in _opener
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/7z/3spcsmdx5n344dh0fb5j0hl40000gn/T/_MEIqfmicz/selenium_stealth/js/utils.js'
.
However, simply running python3 main.py works fine.
Reinstalling selenium-stealth did nothing, I'm unsure what I can try to fix/change from here?
quick turnaround (for issue pls refer to my comment in comments section):
step 1: build the package , refer the command in code section)
step 2: create folder --> dist\your package(in my case slhpackage)\selenium_stealth\js
step 3- copy the js files from https://github.com/diprajpatra/selenium-stealth/tree/main/selenium_stealth/js and put it in folder created in step 2.
and now your executable should run fine.
pyinstaller slhpackage.py # build package (1)
#Python version ==> Python: 3.9.2 (conda)
I used Python 3.9 and encountered the same issue today. As #simpleApp said, I followed the same with least number of modifications and it works for me as of now.
Follow below given steps:
Make sure you that you copy all the files from this link.
Paste all the files in folder_name(might be anthing you wish)/selenium_stealth/js.
[Make sure you that you keep the names selenium_stealth/js with no modifications at any cost, else you'll face conflicts.]
Then run the executable command with the folder_name added.
For convenience, I'm adding it here so that it'd be easier not only for you, but for everyone who uses it.
pyinstaller --noconfirm --onefile --console --icon "dir:\path\to\icon.ico" --add-data "dir:\path\to\folder_name\mentioned\above;." --add-binary "dir:/path/to/chromedriver/chromedriver.exe;./selenium/webdriver" "dir:/path/to/your/python/file.py"
Copy the code, modify it based on your file paths (I've given generic names).
I'd recommend you to make a .bat file for paste the code in it for future use.
Here's the snippet of my code:
#ECHO OFF
color 09
echo Immediate direct Conversion of .py to .exe standalone by PiXinCreate
echo.
pyinstaller --noconfirm --onefile --console --icon "dir:\path\to\icon.ico" --add-data "dir:\path\to\folder_name\mentioned\above;." --add-binary "dir:/path/to/chromedriver/chromedriver.exe;./selenium/webdriver" "dir:/path/to/your/python/file.py"
echo.
echo .exe has been successfully created for .py
echo.
pause.
exit
My code actually creates a onefile, which is standalone executable, in the terminal window.
You can remove the icon part if not needed.
Feel free to revert back if anything goes wrong.
The error that you're getting indicates that maybe something is wrong with the path of the file.
Make sure that the file utils.js exists at the path where it's trying to be located.
If not you could try to download it externally and placing it inside that path. I don't think that would be a good recommendation though.
first remove --onefile from the command and build the app, after building you would find selenium-stealth folder inside of the folder that apeared after build,put this folder(js) inside of selenium-stealth and run the app.
i was looking for solution and it worked for me.

ModuleNotFoundError: py3k for PyInstaller + savReaderWriter

I want to use PyInstaller with module savReaderWriter. My code is very simple:
import savReaderWriter
print("hello world")
input("Press enter, to finish...")
I was trying to use hidden import with appropriate module:
pyinstaller --clean --win-private-assemblies --upx-exclude=vcruntime140.dll --onedir --hidden-import="savReaderWriter" temp.py
pyinstaller --clean --win-private-assemblies --upx-exclude=vcruntime140.dll --onedir --hidden-import="py3k" temp.py
pyinstaller --clean --win-private-assemblies --upx-exclude=vcruntime140.dll --onedir --hidden-import="py3k" --hidden-import="savReaderWriter" temp.py
But in all cases I have received the same error:
ModuleNotFoundError: No module named 'py3k'
I solved the issue by including the path of the savReaderWriter to the parameter.
pyinstaller -p "C:\PyProjects\test\venv\Lib\site-packages\savReaderWriter"; test.py
Also, the real pain is when you trying to delete the module, an Error will occur because it is finding a non "UTF-8" character.

pywintypes.error - Using pyinstaller to create a one-file bundled executable

Running Powershell in the same directory as:
pyinstaller --onefile --icon=<my_Logo.ico> BC-USD.py
It always end up with the same error:
pywintypes.error: (2, 'LoadLibraryEx', 'The system cannot find the file specified.')
How can I fix this?
Does your code import a dll? If so, you need to tell pyinstaller to include it using the --add-binary or --add-data option:
pyinstaller --onefile --icon="icon.ico" --add-binary "current/path/to/dll/my_dll.dll; folder/to/store/dll/inside/pyinstaller/bundle"
http://pyinstaller.readthedocs.io/en/stable/usage.html

Categories