Full width home advertisement

Travel the world

Climb the mountains

Post Page Advertisement [Top]

">

Converting Python scripts into executable programs - Windows

py2exe is a Python extension which converts Python scripts (.py) into Microsoft Windows executables (.exe). These executables can run on a system without Python installed.

Installing py2exe

For Windows systems, you can download a third-party tool called 'py2exe'.
  1. Run the Command Prompt.
  2. Change to the Python\Scripts directory
  3. Download py2exe using the built-in utility pip:
   pip3 install py2exe


Converting a script into an executable
  1. For each script file that needs to be converted into an executable, a setup script file needs to be created. Assuming that test.py is to be converted into an executable, a setup.py file should be created with the following lines of code.
   from distutils.core import setup
   import py2exe
   setup(console=['test.py'])

  1. Run this script from command-line
   python setup.py py2exe

  1. Two directories will be created when you run your setup script, build and dist. The test.exe will be stored in dist directory.
   C:\test>cd dist
   C:\test\dist>test.exe




Converting Python scripts into executable programs - Linux

Using chmod in Linux
  1. Open terminal window from Linux GUI.
The chmod command changes file attributes. Every file has read, write and execute attributes. Any attribute can be set or unset by + or – operator. To make test.py an executable use following command
   $ chmod +x test.py

You no longer need to execute test.py with Python interpreter. Instead test executable script is run by following command
   $./test

No comments:

Post a Comment

Bottom Ad [Post Page]

">
| Designed by Colorlib