How to Run a Python Script Without Python

While it is nearly always possible for someone to download and run a local installation of Python, sometimes, due to reasons of security or user education, installing the Python interpreter is not feasible, and the Python coder has to convert his code into something that will run independently. This can be done for Windows operating systems via the py2exe toolset.

Python is an open-source, freely available programming language that also has a dedicated interpreter. Python is built around rapid software development, concise, easy to read (and maintain) code, and one of the most commonly used scripting languages on the Internet.

Things You'll Need

  • Python Interpeter, available at www.python.org
  • py2exe, available at www.py2exe.org
  • An existing Python script you want to convert.
Show More

Instructions

    • 1

      Download py2exe.py and install it in the directory with your other Python modules.

    • 2

      Create a new text file named setup.py. This will be used to convert your existing Python script into a Windows executable file.

    • 3

      Copy the following code into setup.py:

      from distutils.core import setup
      import py2exe
      setup(console=['script.py'])

    • 4

      Change the name “'script.py'” to the name of your Python script.

    • 5

      Launch the Python interpreter, and enter the following command:

      setup.py py2exe

      The script will run, and you will have an executable named script.exe, where the word “script” is replaced with whatever the name of your Python program was. It will be in your “dist” subdirectory under Python, but will work no matter where you put it.

Tips & Warnings

  • To make a graphical user interface executable with py2exe.py, you need to call on the GUI tools in the Tk+ Interface distributed with Python; the procedure to make the executable does not change.

  • Mac OS X and every distribution of Linux already come with Python installed; they do not need this procedure to run.

Related Searches:

References

Comments

Related Ads

Featured