How to execute pyinstaller exe on MacOs on click - python

I'm using pyinstaller to generate an executable using the command:
sudo pyinstaller --onefile --windowed myapp.py
which generates an executable and a MacOs App. The issue is I want the terminal to open for the user to use the script. When I click on the app, the app opens an closes; which from what I've gathered is expected if it's not using a GUI. But the exe when I click on it just opens a terminal instead of running the script. If I open a terminal and use a command like
./myapp
then the application correctly executes. What should I do to remove the process of having to open a terminal?

On Mac OS X, the --windowed option has the opposite functionality that you desire:
-w, --windowed, --noconsole
Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. This option is ignored in *NIX systems.
See the description of the options here. Could you try removing this option and running pyinstaller again?

Related

PyInstaller-produced executable works from Conda shell but not normal shell

I have a .pyw file that I packaged into an executable (on Windows 10) with the following command from my Conda shell:
pyinstaller --onefile myfile.pyw
I can successfully run (it's a PySimpleGUI GUI, so "the GUI window loads" is the definition of success here) my application with (again from a Conda shell):
./dist/myfile.exe
However, if I run this same command from the same folder in a normal windows Command Prompt, nothing happens (no error, but the GUI window does not load). If I double click the exe from Windows Explorer, it also does not load (and again no error of any kind is displayed).
What do I need to do so that I can double click this exe and have it open the GUI?

Pyinstaller executable can't run on other machines (OS X)

I am trying to package my python script (a script that asks for user input and runs solely in the Terminal window on mac). I package the application using 'pyinstaller' and the following code:
pyinstaller --oneapp my_script.py
This creates an executable in the dist folder in my targeted folder, and I can run the executable no problem. However when I try to send this application to my coworkers, the file is not recognized as an executable and opens in text editor. Trying to run the file from terminal on another computer will provide no result either.
If you specify only --onefile under Mac OS X, the output in dist is a UNIX executable myscript. It can be executed from a Terminal command line. Standard input and output work as normal through the Terminal window.
Have you tried executing it in terminal?
source: https://pyinstaller.readthedocs.io/en/v3.3.1/usage.html#building-mac-os-x-app-bundles

How to "compile" a python script to an "exe" file in a way it would be run as background process?

I know how to run a python script as a background process, but is there any way to compile a python script into exe file using pyinstaller or other tools so it could have no console or window ?
To run an executable generated with Pyinstaller without a console window, use the --noconsole flag (pyinstaller --noconsole my_file.py).
Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. This option is ignored in *NIX systems.
See the documentation for more information.
If you want to run it in background without "console and "window" you have to run it as a service.

Pyinstaller on Kali to create exe for Windows XP

I am using Pyinstaller on Kali Linux 2 to create .exe to run on Windows XP.
So far, pyinstaller is successful at creating .exe that works on Kali Linux, but not Windows
Here is the python code
import webbrowser
webbrowser.open('http://www.cnn.com')
This is the command I ran on Kali Linux
~/Downloads/PyInstaller-3.2/pyinstaller.py --onefile --windowed --noupx open.py
When I open the resulting open.exe in Kali, it opens www.cnn.com. But if I email this attachment and open in Windows XP, it asks
When I save and try to execute, it says ..... How to troubleshoot this?
And when I click open is shows following. How to make it open with double-click?
From the PyInstaller documentation:
If you need to distribute your application for more than one OS, for example both Windows and Mac OS X, you must install PyInstaller on each platform and bundle your app separately on each.
So, to make an app which runs on Windows, you have to create it using PyInstaller on Windows.
Rafalmp is correct you must use a Windows machine to compile it. Alternatively you can use Wine, if you didn't have access to a Windows machine.
For more info please refer to Pyinstaller FAQ
Windows Defender assumes that externally sourced executables, especially those without cryptographic signature, may be malware. Try clicking "Open."

Tkinter program converted to .app using PyInstaller closes immediately

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.

Categories