0

I want to know if there are a way to create a executable file to a python program (in linux or windows).

Imagine a person that doesn't know how to open the terminal but want to use the program, I want to create a executable file which that person only have to click on it and the program opens.

thanks

2 Answers2

1

I use the command

c:\pyinstaller\pyinstaller.py --onefile --console my_script.py

it works like a charm ;) (note only applies to windows) ... if theyre using linux they should be really comfortable in a terminal

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
0

Well, there are many possibilities to both do what you ask and to answer your question.

The simplest answer would be thus: On windows, with a Python interpreter installed, it registers the .py, .pyc and .pyo file extensions to be opened using the told Python interpreter and thus you get a free "double-click-to-run" behavior. On Linux, a similar behavior can be achieved by telling the loader which interpreter to use in order to run the script by adding the following line as the 1st line in the file:

#!/usr/bin/python -O

and marking it as an executable using chmod +x myfile.py.

This will allow a user to run your file with a double-click from whatever file explorer he uses.

As for other possibilities, there are quite a few solutions, I'd recommend you to run a google search for it. For Windows I'd recommend py2exe, and I'm not familiar with Linux solutions, and, anyway it was discussed on StackOverflow here

Best of luck!

Community
  • 1
  • 1
immortal
  • 3,118
  • 20
  • 38
  • ok, but were I write "chmod +x myfile.py"? In terminal on script's path? – user3137608 Jan 20 '14 at 13:00
  • `chmod` is a unix shell command that changes the file access mode. `chmod +x` marks the file as an executable and allows the user to run it. This needs to be done from terminal and `myfile.py` here is your script. – immortal Jan 21 '14 at 21:17