py2exe - single file exe-tkinter program not executing - python

I used below code to make execute of my program:
from distutils. core import *
import py2exe,sys,os
sys.argv.append('py2exe')
setup(options={'py2exe':{bundle_files':1,'compressed':True,'includes':["Tkinter",]}}'windows=['trial.py'],zipfile=None,)
It is creating single file .exe, but not executing.
same code with bundle_file 3 (without single file) is working fine.
trial.py:
import Tkinter
Tkinter.Tk()
mainloop()
Please help me to create a single .exe file for GUI program

PyInstaller is a much easier option that can be used from the console. Just pip install pyinstaller, enter your program's directory, and pyinstaller yourscript.py.
I am confused that you say trial.py is working fine when I get an error on my machine. mainloop() needs to be replaced by Tkinter.mainloop().

Related

Converted .py file to .exe and .exe file wont open properly

So I recently managed to convert a .py file into .exe but the problem is that the .exe file wont open properly. Basically what happens is the command prompt opens for a second and then shows some code for 1 milisecond and closes. I did manage to get a screenshot of what the command prompt says.This keeps happening when I try to open it but not with just that file, but every .py file I convert into .exe
I made a simple code to check if it was only like that for my previous code but its for every code that I make. I also used PyInstaller to convert the .py file into a .exe
import customtkinter as tk
import sys
import os
root = tk.CTk()
root.state('zoomed')
root.wm_title("Test File")
frame = tk.CTkFrame(master=root, height=300, width=600)
frame.pack_propagate(0)
frame.pack(pady=200)`
lbl = tk.CTkLabel(master=frame, text="I like chicken nuggets.", font=("Bahnschrift", 30))
lbl.pack(pady=120)
root.mainloop()
If something is unclear about my explanation, please ask. Im on Windows 11 and I use VS Code.
I asked for help on Discord but no luck. Im hoping somebody could help me here. I want my .exe file to open up like a charm and do its job.
I suggest using auto-py-to-exe since it's easier to use. To install type this:
pip install auto-py-to-exe
To run type this:
auto-py-to-exe
Then you'll see something like this:
Add the path to your script and you can change any setting you want
Then you'll need to add the path to your custontkinter package
Go to Additional Files -> Add Folder -> locate your python folder -> Lib -> site-packages -> customtkinter and add it to your exe
Scroll down and you'll see this button. Press it and your exe should work

Python: no module named 'bottle-websocket' when running an executable made with PyInstaller, including Eel module

I was playing around with the eel module for Python - gives an opportunity to run HTML + CSS/JS with the python functionality.
Made a simple program, tried to make an executable out of it via PyInstaller.
No errors whatsoever, but when running this executable it crashes on the first line - import eel, telling - there is no module called 'bottle-websocket'.
I checked pip: eel, bottle-websocket are installed. Can't figure out what's the problem. Attachments:
main.py:
import eel
from os import path
eel.init(path.dirname(__file__) + "/web")
eel.start('main.html', block=False)
while True:
eel.sleep(10)
Error:
Picture with the error while I try to start the exe
EDIT:
PyInstaller Log
I was also having this same issue, but I finally fixed it, it was actually very very easy, first of all make sure you are using auto-py-to-exe to package your app.
After inserting necessary details (script file,, extra files etc), you would see an advanced options tab probably below, click on it to expand it, look for the hidden imports label and insert "bottle-websocket" in the input field representing the hidden imports, that's basically all you need to do
I HOPE THIS HELPS
Took me the whole day figuring out the solution, but finally, here it is:
Copy the plugin.py, server.py files from C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bottle_websocket to C:\Users*YOUR_USERNAME*\AppData\Local\Programs\Python\Python36-32\Lib
Make sure you have this line as follows in your *.spec file generated by PyInstaller (FOR PYTHON 3.6 32bit):
datas=[('C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\eel\eel.js', 'eel'), ('PATH_TO_YOUR_WEB_FOLDER', 'YOUR_WEB_FOLDER_NAME')]
3)Run this command in cmd: python C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\eel\main.py HERE_SHOULD_BE_THE_PATH_TO_YOUR_WEB_FOLDER
this command will get the 'bottle-websocket' work and will make sure that it complies with the web folder and files.

Python program using tkinter closes immediately in Windows 10

Code in question:
from tkinter import *
root = Tk()
test_label = Label(root, text = "Hello")
test_label.pack()
root.mainloop()
I can only run this python code from the IDLE, if I run it any other way the window flashes on the screen and closes immediately. I've tried:
-adding an "input" line to keep it from closing
-running from the windows powershell
-compiling the code into an EXE with pyinstaller
and now I can't find any other suggestions. I tried making a simple 1-line program that just asks for input, and that works normally and stays open fine. The tkinter program works fine in IDLE but not any other circumstance.
What's happening here?
EDIT: If I run the program from the command line instead of windows 10 powershell, I get the following output:
Traceback (most recent call last):
File "C:\Users\Cam\Desktop\CSCI Notes\Programs\test.py", line 1, in
<module>
import tkinter
ImportError: No module named tkinter
However, the tkinter file is in the python library on my computer, and importing tkinter in python shell or IDLE works fine.
When I run python on command prompt, it shows python 2.7, so I changed tkinter to Tkinter and the program worked by importing the .py file
Using cmd:
Pyinstaller works(through canopy cmd prompt):
the first line is what I put into my IDLE's cmd prompt
Which populates the folder when executed:
And inside dist, I run test.exe which shows the window
NOTE: my system command prompt is using python 2.7 while the canopy(python environment) command prompt uses 3.5 with pyinstaller
Okay, I think I've solved this one! I read that windows can sometimes try to open .py files with python 2.7 instead, even if they're written in 3.6. I uninstalled python 2.7 from my computer, and now the file runs normally.
So for anybody having this problem, try to make sure your computer is opening python 3, not python 2.
I have also had this problem and as far as I can see no one has a proper solution.
The best I have found is putting -i before your filename. For example:
python -i yourfile.py
this will start the IDLE in the command line
This could also happen if you are using a modulo that isn't installed in your computer even if you have installed it using your IDLE. Try installing it with the command "pip install modulo" else try installing it manually.

Trying to use Py2exe, keep getting errors

I have small program made in python with selenium, and now I'm trying to make an .exe with py2exe.. I get the exe but when I run it, terminal just pops up for split second then it terminates.
I tried to run .exe in cmd and It says that there is no such file as webdriver_prefs.json
Here is the setup.py I have:
from distutils.core import setup
import py2exe
setup(console=['file_name.py'])
Any input on how to resolve this is welcome.
Cheers.

how make python program run hidden mode in .exe format?

I have a python program that run without console in app.pyw file format. I converted that program to .exe file using py2exe using this script
from distutils.core import setup
import py2exe
setup(console=['app.pyw'])
now the app.exe application working fine,but app will not work without console window. I want to run my app without console window in .exe format
(I cant add a comment )
I suggest that you read the module 'distutils.core' where setup is defined.
The para 'console=['app.pyw']' might be your problem.
Here you don't need to add .pyw just edit your py2exe setup script
replace console=
by windows=
should be something like that:
from distutils.core import setup
import py2exe
setup(windows=["app.pyw"])
try setup(windows=["name"]) instead of console. When theres no GUI window to run maybe itl hide it..

Categories

Resources