1

For an example I have created welcomeGUI.py file with has a simple GUI as follows using Tkinter.

from Tkinter import *
import ttk

class Application():

    def __init__(self, master):
        frame = Create_widgets(master)
        frame.pack()

class Create_widgets(Frame):

    def __init__(self, master):
        Frame.__init__(self, master)

        self.toplabel = Label(master, text="Welcome!", font=('cambria', 20, 'bold'),
                         fg="white", bg="Midnight Blue")
        self.toplabel.pack(fill=X, ipady=100)

        statuslabel = Label(master, bg="Midnight Blue")
        statuslabel.pack(fill=X)
        self.midlabel = Label(master, text="Device ready,connect a flash drive to continue...",
                         font=('Ubuntu-L', 12), fg= "white", bg="Midnight Blue", anchor="n")
        self.midlabel.pack(fill=X, ipady=5)

        bottomlabel = Label(master, bg="Gainsboro")
        bottomlabel.pack(side=BOTTOM, fill=X)

        button1 = ttk.Button(bottomlabel, text="Close")
        button1.pack(side=BOTTOM)

#**** Main ****

root = Tk()
root.title("Projector Plus")
root.configure(bg="Midnight Blue")
root.minsize(550, 550)

pro = Application(root)

root.mainloop()

Then I need to create this file that can be installed on Ubuntu(To create an executable file on Ubuntu). In Windows this is done very easily with .exe file(Using cx-Freeze). Really I have no idea about the file system of Ubuntu and shell files.

Please help me to get an idea about this problem. I don't have any idea how to enter this matter.

5
  • stackoverflow.com/questions/12089254/… This link could be of assistance. Commented May 10, 2015 at 9:41
  • do you mean including other libs or is it just Tkinter? Commented May 10, 2015 at 10:18
  • You can also use PyInstaller - it is crossplatform Commented May 10, 2015 at 10:40
  • @PadraicCunningham Yep, including other libs in OpenCV? How do I bundle them in to one executable file? Commented May 10, 2015 at 10:45
  • Having opencv as a dependency won't be easy, it has dependencies of it's own. Commented May 10, 2015 at 11:05

2 Answers 2

3

Basically, to make a file executable in Unix systems, you just have to do one thing: allow it to be executed (very surprising ;) ). To do it, you must use the chmod command as follows: chmod +x youfile.py. The +x add the right to be executed.

Now, your system will allow you to execute the script, but for now it's just a simple text file... Ubuntu doesn't know that he must use the python command to run it, so you'll have undermined comportment. To resolve this, we use the sha-bang line (for more information, see the wikipedia page): at the first line of your script, you must write #! program_to_use, in your case it's python. Generally, we take benefit of the env variables, and use #! /usr/bin/env python, but you can also choose yourself the version of python you want, doing #! /usr/bin/pythonX.X where X.X is the version of python.

Sign up to request clarification or add additional context in comments.

3 Comments

This works well in Ubuntu. But what I should do if I used some codes with OpenCV in my welcomeGUI.py and run this code on Raspberry Pi( without installing OpenCV in Raspberry Pi ) ? Should I install OpenCV in Raspberry Pi or is there any alternative ways to do that task ?
I've never used OpenCV, but you could either install it using pip, if your raspberry is connected to the internet, or try to create a standalone python (see here for example). Finally, you can try to pick up the openCV files (in /use/lib maybe) and copy them with your executable: it may work.
the notion of executable(main meaning) has nothing to do with Unix. it is only a Turing machine code(aka machine code) that is to be run DIRECTLY on a universal Turing Machine which we modernly call computer(it's actually processor). Everything that really executes does so in a machine code. +x permission on Linux has nothing to do with it: a perfectly readable bash text script should be made runnable and is obviously not a machine executable.
0

1 - Add on the top of your file this line: #!/bin/env python (This may differ depending on your ENV variable)

2 - make your file executable by:

a - In Unix system, run the following command:

      `chmod +x myfile.py`

b - In Windows System, you can use the utility py2exe found on http://www.py2exe.org/

more on this can be found at:

https://docs.python.org/2/faq/windows.html#how-do-i-make-an-executable-from-a-python-script

2 Comments

This works. Can I do the same way for any kind of python files ? I mean If I used OpenCV in my .py file and if I run this code a machine with out having installation of OpenCV.
Yes it will, as stated on the tutorial page of py2exe: "py2exe turns Python programs into packages that can be run on other Windows computers without needing to install Python on those computers. Python is needed on the computer where py2exe itself is run because py2exe is a Python program and it includes parts of Python in the package that is built. "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.