I have a Tkinter GUI battleship game application I wrote that I am trying to convert to a .app file so I can run it easily on Mac OS X computers. After cding to the directory with both the main .py file, and all the subfiles (three other python files, a json file, and an icon file), I am executing the following command:
pyinstaller --onefile --windowed --icon favicon.icns --name Battleship battleship.py
This produces two files in the "dist" folder: Battleship and Battleship.app. The Battleship.app has the icon I specified in the command above.
When I run the non .app file (via double-clicking it), a terminal window opens and my Tkinter GUI opens and works (from the little testing I did) flawlessly. However, I would like only the GUI to open, without the terminal.
This is supposedly the purpose of also producing the .app file. However, when I run the .app file (via double-clicking it), it's icon merely bounces a few times in my application bar at the bottom of my screen, and then disappears. No actual window is opened.
How do I make it so when I double-click the .app file, my application's GUI actually opens (without a terminal window)?
Thanks in advance.
Note: I am using Python 3.5.1
RoberR seems like you are missing some necessary packages while building app from pyInstaller, I would suggest your to use:
pyinstaller --onefile --icon favicon.icns --name Battleship battleship.py
it will display your terminal and you would be able to figure out what is happening, in case of missing package please use:
pyinstaller --onefile --hidden-imports=file_name --icon favicon.icns --name Battleship battleship.py
Hope this solves your problems.
It is definitely an issue with Tkinter that crash when using the doubleclick on the .app. The only workaround I found was to use "brew python3" instead of "anaconda python3".
Reposting myself from: https://stackoverflow.com/a/57818744/10143204
There is a few issues with the tcl version that comes with python, discussed here. I've written an script that automatically changes the init.tcl file to the correct version.
N.B. you shouldn't use the --onefile flag as the file directories aren't present, and the script won't work.
cd /path/of/your/app
git clone https://github.com/jacob-brown/TCLChanger.git
pyinstaller --windowed app.py
python TCLChanger/TCLChanger.py
You should now be able to open your app, from the terminal and via double clicking.
Related
Please tell me how to package my project correctly in exe and bin.
I have tried to do it via nuitka on Linux and virtual Windows.
On Linux, I use this command:
python -m nuitka --standalone --follow-imports --output-dir=relize-linux --enable-plugin=tk-inter --enable-plugin=numpy --disable-console --product-name=aigod --linux-icon=aigod.ico --linux-onefile-icon=aigod.ico main.py
On the virtual Windows environment, I use this command:
python -m nuitka --standalone --follow-imports --output-dir=relize-windows --enable-plugin=tk-inter --enable-plugin=numpy --windows-disable-console --windows-icon-from-ico=aigod.ico --windows-product-name=aigod --lto=no main.py
Compiling and running the binary, both give me the same result (not opened), a pop-up window, supposedly a startup error.
The main file is just a GUI menu on tkinter, although this menu should have shown.
I also tried pyinstaller, but still cannot run the binary correctly.
I can't figure out why this happens.
upd-----------------------------------
I managed to compile the project using the command:
python -m nuitka --standalone --follow-imports --output-dir=relize-linux --enable-plugin=tk-inter --enable-plugin=numpy --disable-console --product-name=aigod - -linux-icon=aigod.ico --include-package-data=classify --include-package-data=data --include-package-data=models --include-package-data=segment --include-package- data=utils main.py
But the catch remains, I have additional scripts that are called via import script2 at the right time. As I understand it, their dependencies were not determined and the project did not introduce them, plus they are in the main folder along with the main script. I tried putting them in a separate folder and trying to account for them with --include-package-data=otherfiles, but that didn't work. Tell me how to take them into account too, they are important because the main script is just a menu, and the rest of the scripts do all the work. Of course, I will try to look at what it writes in the console during the next package, since in this one I indicated without a console.
I tried to convert my python gui application (.py ) to an executable file(.exe) using the pyinstaller module. I ran the following command in the terminal -
pyinstaller.exe --onefile -w sourcecode.py
The process was completed successfully and I got the .exe file(sourcecode.exe) along with the extra folders like pycache and sourcecode. But when I tried to run the .exe file/application by double clicking on it the app didn't start up and gave an error. Please help.
Try adding this --hidden-import to pyinstaller.exe --onefile -w sourcecode.py in case of hidden modules.
You can also try adding --debug to see what the error actually is.
In windows, we can use pyinstaller to build python code like Tkinter to an exe file for user use, How to in Linux, I don't like user to do it in terminal to run the code, Any advice? Thanks,
Linux comes with Python preinstalled, so on Linux you can just prepend a shebang #! line with the path to the interpreter to a Python script and then set the executable bit +x on the file with chmod. Then you can run it by name or click on it in the file explorer application.
If you need more than one file, you can use the zipapp module to group a folder together into a single executable .pyz archive with the shebang.
I have coded a program in Python 3.5 that uses the Tkinter import. I'm trying to figure out a way to run it on computers that don't have Python. First I tried freezing it but I haven't been able to because none of the freezing tools I found support Python 3.5. Then I tried possibly using a online idle but I couldn't find any that support Tkinter. I would prefer to be able to get a .exe file or something similar but if I could run it online that would be good too any ideas?
EDIT
So I have now successfully downloaded PyInstaller using pip. My current problem is when I type this into the console: pyinstaller.exe --onefile --windowed Finder.py
I get this error: 'pyinstaller.exe' is not recognized as an internal or external command,
operable program or batch file.
EDIT
I have now found the pathway to pyinstaller.exe. Now when I try to use it it says Access is denied.
I finally figured it out after about three days of work. Fist I downloaded PyInstaleller in the zipped form and extracted it. Then I put my program in the PyInstaller folder. Then I opened a regular command prompt. I then typed cd then the location of the PyInstaller folder. Finally I typed pyinstaller.py --one file --windowed program.py. Then when I went into the PyInstaller folder there was a folder called program with the .exe file in the dist folder. Thanks everyone for all of your help!
You can use pyinstaller to do that. I think its work fine on linux em linux.
Another option is use py2exe.
Try pyinstaller -F -w Finder.py as the command or you could check out CxFreeze.
I have a script (Shell, chmod-ed to 755. Python is in the script, meaning not run from an outside .py file) that is executable. It works when I run it. How can I make a .app that executes said script on runtime? I have a simple .app that has this structure: APPNAME.App>Contents>MacOS>script
This does not run. Is there any way I can piggyback a script onto another application, The Powder Toy, for example? I'm not new to OSX, I just don't have root privileges and can't install XCode.
Rembember, I can't install anything from source or use setup scripts, effectively annihilating py2app as an option.
EDIT:
This answer is courtesy of mklement0. Automator lets you choose the environment to run your script, type it in, and bundle it into a .app, removing the need for a shell script.
Run Automator and create a new Application project.
Add a Run Shell Script action.
In the Shell: list, select the interpreter of choice; /usr/bin/python in this case.
Paste the contents of your Python script into the action and save the *.app bundle.
if your using applescript, just save it as a bundle by save as, and click the drop down saying script, change that to bundle i think. after that, click on the bundle icon in apple script and drag the script to the folder you want. to run it put your run command in and drag the script that you placed in the bundle folders before in the directory slot of the run command. i can not give you anything exact due to the fact that i am not on my mac, but i am giving you the best i know.