I made a a simple GUI program in python with tkinter and attempted to convert it to an .exe using py2exe. However, I've run into a problem. When I try to run the exe it flashes an error very quickly then disapears. So the best I could do was take a screan shot of the error.
How do I go about fixing this?
Edit
Velociraptors, this is my setup file. It's about as basic as it can be. How would I go about integrating init.tcl into the code?
from distutils.core import setup
import py2exe
setup(console=[r'C:\Python26\Random Password Generator.py'])
Does your setup.py script include init.tcl in the data_files option? The py2exe list of options says that's how you should include images and other required data files.
Edit:
Your setup script specifies that your program should be converted to a console exe. If you want a GUI program (which you do, since you're using Tkinter), you need to use the windows option:
setup(windows=[r'C:\Python26\Random Password Generator.py'])
Py2exe should correctly include Tkinter's dependencies. If not, you can manually include init.tcl:
setup(data_files=['C:\Python26\tcl\tcl8.5\init.tcl'],
windows=[r'C:\Python26\Random Password Generator.py'])
Ensure that tcl is installed in C:\Users\splotchy\lib\tcl8.5 or C:\Users\lib\tcl8.5.
If you want to see the error messages for longer, run your program from a command prompt.
I found a bug on the virutalenv site which suggested the following https://github.com/pypa/virtualenv/issues/93
for windows in your directory "C:\Environments\VirtualEnv\Scripts\activate.bat" just add which are set to the right path to TCL and TK for your python version
set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python27\tcl\tk8.5"
restart your cmd or shell
I believe that the TCL location have changed from there default ones.
Related
I have created a python script that I am attempting to turn into an application on mac so that I do not have to alway open the terminal. I am using Tkinter to create a window that the script runs on.
I run pyinstaller --onefile -w -i "Icon Name" "myapp.py" and I get the Dist folder with both a unix script and a macOS application. Running the Unix Script works perfectly fine, however when I try and run the app it will breifly blink in the taskbar and then dissapear without doing anything. running open myapp in the terminal opens it fine, its just when I double click on it.
I have tried looking it up and PyInstaller App not opening on Mac leads me to this github thread https://github.com/pyinstaller/pyinstaller/issues/3753. I tried following along however when I get to the hook-_tkinter.py file mine is only 30 lines of code and looks like this:
import sys
from PyInstaller import compat
from PyInstaller.utils.hooks import logger
from PyInstaller.utils.hooks.tcl_tk import collect_tcl_tk_files
def hook(hook_api):
# Use a hook-function to get the module's attr:`__file__` easily.
"""
Freeze all external Tcl/Tk data files if this is a supported platform *or* log a non-fatal error otherwise.
"""
if compat.is_win or compat.is_darwin or compat.is_unix:
# collect_tcl_tk_files() returns a Tree, so we need to store it into `hook_api.datas` in order to prevent
# `building.imphook.format_binaries_and_datas` from crashing with "too many values to unpack".
hook_api.add_datas(collect_tcl_tk_files(hook_api.__file__))
else:
logger.error("... skipping Tcl/Tk handling on unsupported platform %s",
It does not have the specific lines that the thread is showing I need to edit. I should also note that I found the file in /opt/homebrew/lib/python3.10/site-packages/PyInstaller/hooks/hook-_tkinter.py instead of where the thread is pointing to. I cannot find this file there.
I also read somewhere (I forget where exactly) that I need TCL and tkinter installed which I thought I did already cause it comes with python. trying to find somewhere to download tcl brought me to activetcl but I am unsure how to install that on my computer so I am not sure if that is the solution or not because I cannot get it working.
Sorry for the long question but would anyone be able to assist me in getting this working?
I created a data-miner GUI for twitter with kivy and am currently having a lot of trouble turning it into an exe. I tried following this video and import glew and sdl2 into my spec but after doing pyinstaller main.spec, my executable still would not open.
Is it because I have more than one files and folders for my program (here is the link to the github repo for my project), if so, how do you deal with that?
In addition, if I manage to success create a working exe, how do I create an exe installer that other people can use to install the executable?
Making an executable from a complex script like yours may become quite frustrating because of its dependencies. But I'm giving you a brief guide about what you need to follow to achieve your goal.
Create your main.spec file with console-mode enabled to see the exact error message for the app. (make sure to remove --noconsole from PyInstaller command or set console=True in spec file). Also use --no-upx in the build command to remove compression from output file (this helps with omitting some DLLs which may cause issues).
You need to make sure that every external module you used can pack correctly. I don't think you get any problem with either Kivy or Tweepy. But if you get any missing import error, try to check the solution for each one by searching the pattern [module] pyinstaller.
Your app has external resources like images, files, etc., which must be added to the packed executable and load properly. I wrote an answer about this here.
If you want a standalone executable, you need to use -F with PyInstaller command, which is more robust than using an installer to gather files in one directory mode.
I wanted to compile my python program that uses pygame into an executable using py2exe but I'm experiencing some problems. I run the script in the windows command line and it seems to work. It creates a dist directory but when I try to open the .exe file, it briefly opens a command line window and then doesn't do anything.
Could this possibly be because I've used pygame and py2exe doesn't support it? Or do I need to put a copy of the pygame library into the same directory as my program?
There is an answer to this on the pygame wiki: http://pygame.org/wiki/Pygame2exe
To include pygame in the executable, you will need to edit BuildExe.__init__
Try running the .exe from the command line to see if it's printing some kind of error message. Probably it's missing some DLLs, which you'll need to manually specify when executing py2exe.
This blog post might be useful.
You should use PyInstaller to turn your program and its dependencies into a standalone executable
https://pypi.org/project/PyInstaller/
Using it is as simple as running pyinstaller /path/to/yourscript.py
Really struggling to get a user input when I run an exe file created by cx_Freeze. If I create a script that requires no input, it runs fine. A black window appears for a second then disappears, and script runs in the background.
The problem is, if user input is required there is no console window to type in
My setup script looks like this:
from cx_Freeze import setup, Executable
setup( name = "SpecialApp",
version= "0.1",
description="Performs useful things",
executables = [Executable("specialapp.py")])
I've tried Base="Console" and Base="Win32GUI" but neither make a difference.
Another thing, this may need its own question, but does anyone know how to run the Exe file without requiring the .dll files to be present? I don't want to give my end users a huge folder full of files, I'd like to give them just the exe file or a bat file if possible.
1) Try adding base = Win32GUI in executables = [Executable("specialapp.py")]) so it looks like:
[Executable("specialapp.py",base = None)])
Note that Win32GUI hides the console.
If that still does not work try running from command prompt (or your OS equivalent) and see if there are any error messages (just because it compiles and starts without errors it does not mean there are any).
2) For single file exe I suggest you go for Pyinstaller or build into an installer with bdist_msi command you could also try IExpress.
3) The DLLs provide the Python runtime libraries so realistically no not with Cx_Freeze.
Hope I helped
I'm trying to turn a program that I've written in Python 2.7 (using tkinter for the GUI) into a standalone executable using py2exe. I've written the following script in a file called setup.py:
from distutils.core import setup
import py2exe
setup(data_files=['C:\Python27\tcl\tcl8.5\init.tcl'] , windows = ["Brand_Counter.py"])
When I run this, the command prompt opens for a second, then nothing happens. As far as I can tell, according to the documentation my code should create a subdirectory "dist" which will contain my executable, but this isn't happening. Does anybody see anything wrong with my code?
To do a build of a py2exe project, you should issue this command from the directory that contains your setup.py file:
python setup.py py2exe
Works well for me.
EDIT ---
In addition you're using the data_files parameter which takes a list of tuples. Your parameter should look something like this:
data_files=[('tclfiles', ['C:\Python27\tcl\tcl8.5\init.tcl'])]
Adjusted for wherever you want to place your init.tcl file. For more examples see this link: py2exe data_files