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
Related
I want to run a specific command from a package that can be only run from terminal, through an executable python script. I have already tried subprocess.Popen(). Running the python script from terminal solves the problem but i want the final script to be able to run with just double clicks(i.e. executable file)
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 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.
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?
I am trying out pyinstaller for the first time. I created a file named hello.py with just one line of code:
print "hello"
I used the following command to make a binary:
pyinstaller hello.py
The process completed successfully and a binary was created at dist/hello. I am not able to run this binary file. When I tried to run it from the terminal, I got,
bash: .: hello: cannot execute binary file
I tried to double click it from nautilus but nothing is happening.
How can I run this binary file?
I am using Ubuntu 16.04
Got it running by typing the relative path dist/hello in terminal
for linux (tested on ubuntu 16.04 python3)
pyinstaller hello.py --onefile it create one file named hello.
Then go inside dist folder use terminal
cd dist.
Then
./hello.
Looks not as windows way , but work. ./hello is something like , run outside...