Compile python executable only for package deployment on Linux

Discussion in 'Python' started by King, Jul 20, 2010.

  1. King

    King Guest

    Hi,

    I have created a simple tool(python script) that creates a self
    sufficient package ready for deployment. Current implementation is
    based on shell scripting to set environment for the app and finally
    execute "python main.py".

    I am planning to convert "main.py" into an executable. The plan is to
    rip the unnecessary code from source code that produce python
    executable such as command line arguments etc, use "main.py" as python
    string (hardcoded inside executable source) and execute it using
    "exec" or similar methods and finally creates executable.

    Am I right here? Is this is the correct approach?

    For example a simple script:

    import os
    import math
    print math.sin(23.0)
    print os.getenv("PATH")

    Once I'll convert above script as i have mentioned above in an
    executable say: "myapp", executing "myapp" will print messages on
    console.

    Cheers

    Prashant
    King, Jul 20, 2010
    #1
    1. Advertising

  2. King, 20.07.2010 18:45:
    > I have created a simple tool(python script) that creates a self
    > sufficient package ready for deployment. Current implementation is
    > based on shell scripting to set environment for the app and finally
    > execute "python main.py".
    >
    > I am planning to convert "main.py" into an executable. The plan is to
    > rip the unnecessary code from source code that produce python
    > executable such as command line arguments etc, use "main.py" as python
    > string (hardcoded inside executable source) and execute it using
    > "exec" or similar methods and finally creates executable.
    >
    > Am I right here? Is this is the correct approach?


    From what you write here, I'm not exactly sure what you want to achieve,
    but...


    > For example a simple script:
    >
    > import os
    > import math
    > print math.sin(23.0)
    > print os.getenv("PATH")
    >
    > Once I'll convert above script as i have mentioned above in an
    > executable say: "myapp", executing "myapp" will print messages on
    > console.


    Assuming that Python is installed on the machine and readily runnable from
    the PATH, this will make the script executable:

    #!/usr/bin/env python

    import os
    import math
    ...

    Note that the file must have the executable bit set.

    Search for "shebang", which is the spelled-out name for the "#!" special
    file prefix.

    Stefan
    Stefan Behnel, Jul 20, 2010
    #2
    1. Advertising

  3. King

    King Guest

    Hi Stefan,

    Well, the idea is similar to package tools like pyinstaller or
    cx_freeze. There approach is slightly different then what I intend to
    do here.

    You have to pass the name of the script to python executable("python
    main.py") in order to execute it. What I mean here is to create python
    executable using python executable source code only(not compilation of
    entire python using source code) and insert "main.py" contents in
    source code(hardcoded) and produce a new executable.

    When you run that executable, it should run the "main.py", which was
    hard coded while building using fixed string or any other method. The
    executable is actually a modified version of python executable. It
    won't take any argument because we'll rip that piece of code out.

    Hope this will clear out.

    Cheers

    prashant
    King, Jul 20, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruslan Spivak
    Replies:
    0
    Views:
    401
    Ruslan Spivak
    Jul 15, 2003
  2. =?ISO-8859-1?Q?Gerhard_H=E4ring?=

    Re: how to compile python program to linux executable

    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Jul 15, 2003, in forum: Python
    Replies:
    0
    Views:
    494
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Jul 15, 2003
  3. sreekant
    Replies:
    0
    Views:
    396
    sreekant
    Jul 18, 2003
  4. Nagaraj
    Replies:
    1
    Views:
    837
    Lionel B
    Mar 1, 2007
  5. Toni Tanskanen
    Replies:
    8
    Views:
    689
    Charles Oliver Nutter
    Dec 18, 2010
Loading...

Share This Page