-1

I want to turn my .py into a runnable programme. I can run it on the command prompt but I want it to run like a real application like Word. Is this even possible?

I am a beginner programmer. I just started learning Python so if there is something really obvious just please tell me in the comments.

  • https://stackoverflow.com/questions/12339671/how-to-compile-python-script-to-binary-executable – 23k Aug 29 '18 at 04:16
  • Possible duplicate of [a good python to exe compiler?](https://stackoverflow.com/questions/14165398/a-good-python-to-exe-compiler) – SanthoshSolomon Aug 29 '18 at 04:17
  • Possible duplicate of [How can I convert a .py to .exe for Python?](https://stackoverflow.com/questions/41570359/how-can-i-convert-a-py-to-exe-for-python) – ivan_pozdeev Aug 29 '18 at 04:49

3 Answers3

3

You're effectively asking how to compile a Python script into an executable. That's not really how Python works, but you can still achieve what you want: an application that installs and runs without requiring the user to know how to start a script from the command line (or install Python for that matter).

Applications like pyinstaller allow you to package your script with just the files it needs for the OS you want to deliver to. https://www.pyinstaller.org

Install pyinstaller into your virtual environment:

pip install pyinstaller

Then test your script and run pyinstaller for it:

python my_script.py
pyinstaller my_script.py

That will create a folder called build with everything needed to build your distributable, and one called dist that has the result including a my_script.exe. A user of your script would need everything in the folder, but nothing else.

If you prefer it to be a single executable, you can run this:

pyinstaller --onefile my_script

This, on Windows, would create a single my_script.exe, but you need to realise that this is just an executable archive that will create a temporary folder somewhere, still containing the same as the dist folder. More about that here: https://pyinstaller.readthedocs.io/en/v3.3.1/operating-mode.html

You can create a nice and simple installer using a tool like InnoSetup, which you can get here http://www.jrsoftware.org/isinfo.php. With it (or another installer builder like it), you can make an installer that puts your packaged script in a folder in Program Files, allow a user to start it from the Start Menu (like an application like Word) and uninstall it when they no longer need it.

Grismar
  • 27,561
  • 4
  • 31
  • 54
0

You can use pyinstaller for creating executables out of python code.

For more information, refer to pyinstaller

Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
0

In gui program:

import tkinter

class EasyFrame(tkinter.Frame):
    def __inputn():
        n=int(entry.get())
        fact=recursive_factorial(n)
        strl="factorial of" + str(n)+"is"+str(fact)
        output_Label.configure(text=strl)
    
    def recursive_factorial(n):
        if n==0:
            return 1
        else:
            return n *recursive_factorial(n-1)

    def __init__(self):
        """ sets up the window and widgets."""
        EasyFrame__init__(self,title='calculate the factorial')
        
        self.Label(text="enter a number to \n calculate the factorial")
        self.ouputLabel(font=("mandeepkaur",12))
        self.entryLabel("mandeepkaur",12,width=6)
        #create the button to calculate the factorial
        Button=calc_Button(text="calculate the factorial",font=("mandeep",12,commandinputn))
        self.addLabel.grid(row=0,padx=10,pady=10)
        self.entry.grid(row=0,column=1,padx=10,pady=10,ipady=10)
        calc_button.grid(row=0,column=2,padx=10,pady=10)
        output_Label.grid(row=1,column=0,columnspan=3,padx=10,pady=10)
        

        mainloop()                         
RiveN
  • 2,595
  • 11
  • 13
  • 26