Running a Python script by double-clicking desktop icon on Mac OS - python

I am very new to programming. I am trying to create a desktop icon that, when clicked on, will run my Python script on Mac OS.
The first line of my code involves input from the user. How can I create a desktop icon of my Python script, that when clicked, allows the user to enter the input in order to cause the Python script to start?
I have tried Pyinstaller; however, when I enter:
pyinstaller "myprogram".py
into the Mac terminal, I receive a "dist" file that includes Python script with an ".exe" file extension. However, when I click on this extension, I receive this response in the terminal window:
logout
Saving session...
...copying shared history...
...saving history...truncating history
files...
...completed.
I would like the Python script to run in order to have a user type their input in order to have the program run. Any help would be greatly appreciated.

Pyinstaller detects the OS and the version you make is only compatible with the system you build it on, they mention that on their page, so it shouldn't be building an .exe; whenever I use pyinstaller on my mac the dist has a .app and a unix executable, you don't have both of those files in there?
also, I just notices your syntax, you should not have the filename in quotations
try:
pyinstaller --clean --windowed --onefile yourapp.py
in your terminal from the directory that has your app. First delete the old folders and .spec it created the first time as well.

Also, I just went through a bundle of issues in a similar vein. If the problem persists after you delete and rerun pyinstaller with proper syntax, check out this page, I have a rather large answer all the way at the bottom, and there are other angles on the same issue there as well.
https://github.com/pyinstaller/pyinstaller/issues/3820

Related

How to make python script autorun on windows startup?

I have a .python script which I convert to .exe file trough autopy-to-exe command and I would like that coverted .exe file always running, so when computer restarts it automaticly starts.
So I want to create in .python script that.
I want to configure it so when somebody downloads .exe file and runs it, that .exe file will be in his startup so next time when he logs in that .exe will be working as well.
The simplest way to accomplish this is by placing it in your Startup directory. Windows will launch anything in there when someone signs in. You may also set this to run when any user logs in by using the "All Users" Startup folder.
This is the filepath for the Startup folder, for your user account:
%appdata%\Microsoft\Windows\Start Menu\Programs\Startupand you can copy and paste that path right into Windows Explorer's address bar to get there. Drop in the .exe and it will launch on the next login.
Reference for Startup folder

How to convert Python package to exe?

Our Programs is not always a Python source file !.
The Python may be associated with a file or an image,
that is located inside the source of the application to the file path inside the package.
For example, when setting the application icon in Tkinter Or Include image for app background
root.iconbitmap('favicon.ico')
PhotoImage(file = 'python_logo.gif')
In Pyinstaller only the source file expires in the exe format.
If the program contains a file or image path inside the source, then the program will not be executed , In that event,The source of the application and files are in a package (on a route).
Please provide a solution to this problem, So as possible convert a package containing source and file into exe
1-Install cx_Freeze, (open your command prompt and type pip install cx_Freeze
2-Install idna, (open your command prompt and type pip install idna.
3-Write a .py program named myprogram.py
4-Create a new python file named setup.py on the current directory of your script.
5-In the setup.py, code below and save it.
6-With shift pressed right click on the same directory, so you are able to open a command prompt window.
7-In the prompt, type python setup.py build
8-If your script is error free, then there will be no problem on creating application.
9-Check the newly created folder build. It has another folder in it. Within that folder you can find your application. Run it. Make yourself happy.
this works on python 3.5 and above!
Add heres the open source project to convert to exe
https://github.com/brentvollebregt/auto-py-to-exe
I have not used Pyinstaller myself but in cx_Freeze I know you can include none project files like images in the setup file. With Pyinstaller you want to look into the spec file. Here is a link to the docs where it talks about added files to project. https://pythonhosted.org/PyInstaller/spec-files.html#adding-files-to-the-bundle I hope thisis of some help.

Pyinstaller exectuable using data from other folders?

I've written a program that generates a random name and displays a random image along with it using Python and tkinter. However, I want the user to be able to add and remove pictures as well as edit the names of students. That being said, I don't want to package these inside the executable where it can't be changed by the user.
To use PyInstaller, I go into the command prompt and navigate to the working directory and type:
pyi-makespec --windowed --onefile --icon=Assets\\icon.ico random_student.py
Then, in the spec file I change datas to:
datas=[('Assets\\icon.ico', 'Assets')],
Then, I run
pyinstaller random_student.spec
The program runs just fine using PyCharm. And I've done this exact same method on a couple of other .py files an it works. However, they don't need to pull images/text into their programs. This will create an executable, but I can't run it. It gives me a Fatal Error "Failed to execute script random_student". I've tried placing the executable in the working directory and in the pictures folder, but neither work.
I'm currently using Windows 10 64-bit and Python 3.6.6
I'd appreciate any kind of help I can get with this!
SOLUTION: I removed the --windowed option so I could actually read the error. Then realized I didn't have Pillow installed so it was unable to be packaged. Thank you for the help.

How to make a Python script run without it opening the console window?

I want to double click on my Python script (which uses a Tkinter GUI) and I just want it to open the Tkinter window, not the console window.
To do this, I changed the extension from .py to .pyw and this seems to work fine on Windows but when I double click my .pyw file on a Linux machine, it doesn't work. It simply froze and I had to restart my system.
Please suggest a platform-independent solution that would help me to run the Python script without opening the terminal/command prompt.
it's been a while since i tried on linux, but i believe it should be fairly simple, firstly you need to put a shebang at the top of the script so your shell knows which executable to use:
#!/usr/bin/python
or if you want a specific version you can expand this to:
#!/usr/bin/python3.2
using whichever version you want (only works for first 2 digits)
then you need to mark it as executable:
chmod 711 myfile.py
for more info on this see this page
then when you double click it, on the rpi (last i used linux) it asks if you want to execute it, or execute it in the terminal.
if you choose to execute it without the terminal, you should only see the tkinter GUI
You can use pyinstaller to create the executables for the different platforms you want.
For example,
The syntax of the pyinstaller command is:
pyinstaller [options] script [script ...] | specfile
In the most simple case, set the current directory to the location of your program myscript.py and execute:
pyinstaller myscript.py
PyInstaller analyzes myscript.py and:
Writes myscript.spec in the same folder as the script.
Creates a folder build in the same folder as the script if it does not exist.
Writes some log files and working files in the build folder.
Creates a folder dist in the same folder as the script if it does not exist.
Writes the myscript executable folder in the dist folder.
In the dist folder you find the bundled app you distribute to your users.
Normally you name one script on the command line. If you name more, all are analyzed and included in the output. However, the first script named supplies the name for the spec file and for the executable folder or file. Its code is the first to execute at run-time.
For certain uses you may edit the contents of myscript.spec (described under Using Spec Files). After you do this, you name the spec file to PyInstaller instead of the script:
pyinstaller myscript.spec
You may give a path to the script or spec file, for example
pyinstaller options... ~/myproject/source/myscript.py
or, on Windows,
pyinstaller "C:\Documents and Settings\project\myscript.spec"
pyinstaller

PyInstaller Issue with Application File Python 2.7

I am trying to use PyInstaller for generating an .Exe from a Python 2.7 file. In the CMD window, I run pyinstaller myfile.py.
It creates a build and dist folder both of which have a number of files, including an Application file. When I click both application files, a CMD box pops up and very quickly disappears, despite my file requiring inputs from the user.
What I am missing here? Which file can I distribute to be a usable copy?
By default, PyInstaller generates a one-folder bundle containing an executable, it also creates this executable with a console window for standard input/output. I'm just guessing, but your script don't have a GUI, right?
In any case, the better way to work is creating a one-file bundle:
pyinstaller -F myfile.py
In this way, you only have to execute one file.
if after executing the application, it behaves in the same way, I would say that adding the -d option will help you to find out what is going wrong with your generated executable. Also, running your application from a per-existing CMD window is recommendable since these windows do not close itself after running your application.

Categories