Need compile python code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mistral

    Need compile python code

    Need compile python code, source is in html and starts with parameters:

    #!/bin/sh -
    "exec" "python" "-O" "$0" "$@"

    I have installed ActivePython for windows.

  • Bjoern Schliessmann

    #2
    Re: Need compile python code

    mistral wrote:
    Need compile python code, source is in html and starts with
    parameters:
    Excuse me?
    #!/bin/sh -
    "exec" "python" "-O" "$0" "$@"
    Is the line break intended?
    I have installed ActivePython for windows.
    What exactly do you want?

    Python code is always compiled (to byte code) before it's run.

    Regards,


    Björn

    --
    BOFH excuse #359:

    YOU HAVE AN I/O ERROR -Incompetent Operator error

    Comment

    • mistral

      #3
      Re: Need compile python code


      Bjoern Schliessmann писал(а):
      mistral wrote:
      >
      Need compile python code, source is in html and starts with
      parameters:
      >
      Excuse me?
      >
      #!/bin/sh -
      "exec" "python" "-O" "$0" "$@"
      >
      Is the line break intended?
      >
      I have installed ActivePython for windows.
      >
      What exactly do you want?
      >
      Python code is always compiled (to byte code) before it's run.
      >
      Regards,
      >
      >
      Björn
      >
      --
      Just to comple python ode - it creates html page, nothing more, nothing
      else.. Just generate one html page.

      mistral

      Comment

      • mistral

        #4
        Re: Need compile python code


        Bjoern Schliessmann писал(а):
        mistral wrote:
        >
        Need compile python code, source is in html and starts with
        parameters:
        >
        Excuse me?
        >
        #!/bin/sh -
        "exec" "python" "-O" "$0" "$@"
        >
        Is the line break intended?
        >
        I have installed ActivePython for windows.
        >
        What exactly do you want?
        >
        Python code is always compiled (to byte code) before it's run.
        >
        Regards,
        >
        >
        Björn
        >
        --
        Just to comple python ode - it creates html page, nothing more, nothing
        else.. Just generate one html page.

        mistral

        Comment

        • MonkeeSage

          #5
          Re: Need compile python code

          mistral wrote:
          Just to comple python ode - it creates html page, nothing more, nothing
          else.. Just generate one html page.
          I *think* this is what you want:

          python -O -m py_compile file.py
          python file.pyo

          See: http://docs.python.org/lib/module-pycompile.html

          Regards,
          Jordan

          Comment

          • mistral

            #6
            Re: Need compile python code


            MonkeeSage писал(а):
            mistral wrote:
            Just to comple python ode - it creates html page, nothing more, nothing
            else.. Just generate one html page.
            >
            I *think* this is what you want:
            >
            python -O -m py_compile file.py
            python file.pyo
            >
            See: http://docs.python.org/lib/module-pycompile.html
            >
            Regards,
            Jordan
            ----------
            this not work for me, show compilation error. Is there simple way
            compile pythone file? its absolutely unclear with command line. Just
            show me exact command I need run(from python interactive shell?)

            Comment

            • MonkeeSage

              #7
              Re: Need compile python code

              mistral wrote:
              this not work for me, show compilation error. Is there simple way
              compile pythone file? its absolutely unclear with command line. Just
              show me exact command I need run(from python interactive shell?)
              OK...

              # cd to where the file.py is
              $ cd /some/dir

              # start python interactively, enable optimized compiling
              $ python -O
              ....

              # import your file.py -- if this doesn't work then
              # your file has errors and will not compile --
              # if it works then your file is now compiled --
              # file.pyo should now exist with file.py
              >>import file
              # you can also do it explicitly --
              # import the compiler
              >>import py_compile
              >>py_compiler.c ompile('file.py ')
              If that still doesn't work, show us the error, or we can't help you
              very easily.

              Regards,
              Jordan

              Comment

              • MonkeeSage

                #8
                Re: Need compile python code

                MonkeeSage wrote:
                >import py_compile
                >py_compiler.co mpile('file.py' )
                ^^^^^^^^^^^

                Should be:
                >>py_compile.co mpile('file.py' )

                Comment

                • mistral

                  #9
                  Re: Need compile python code


                  MonkeeSage wrote:
                  mistral wrote:
                  this not work for me, show compilation error. Is there simple way
                  compile pythone file? its absolutely unclear with command line. Just
                  show me exact command I need run(from python interactive shell?)
                  >
                  OK...
                  >
                  # cd to where the file.py is
                  $ cd /some/dir
                  >
                  # start python interactively, enable optimized compiling
                  $ python -O
                  ...
                  >
                  # import your file.py -- if this doesn't work then
                  # your file has errors and will not compile --
                  # if it works then your file is now compiled --
                  # file.pyo should now exist with file.py
                  >import file
                  >
                  # you can also do it explicitly --
                  # import the compiler
                  >import py_compile
                  >py_compiler.co mpile('file.py' )
                  >
                  If that still doesn't work, show us the error, or we can't help you
                  very easily.
                  >
                  Regards,
                  Jordan
                  ---

                  No, something is wrong there. what I need is just compile one python
                  file which will generate html page, with parameters:
                  "exec" "python" "-O" "$0" "$@"

                  just need simple way do this(script is correct), i will not set any
                  patches anywhere, can i do this wrom normal GUI?

                  Comment

                  • Carsten Haese

                    #10
                    Re: Need compile python code

                    On 23 Sep 2006 12:24:58 -0700, mistral wrote
                    No, something is wrong there. what I need is just compile one python
                    file which will generate html page, with parameters:
                    "exec" "python" "-O" "$0" "$@"
                    This is not a python script. It appears to be a Unix shell script that calls a
                    python script.

                    Maybe it would help if you told us exactly what you're trying to accomplish
                    and why you think you need to "compile python code".

                    -Carsten

                    Comment

                    • MonkeeSage

                      #11
                      Re: Need compile python code

                      mistral wrote:
                      No, something is wrong there. what I need is just compile one python
                      file which will generate html page, with parameters:
                      "exec" "python" "-O" "$0" "$@"
                      >
                      just need simple way do this(script is correct), i will not set any
                      patches anywhere, can i do this wrom normal GUI?
                      Hmmm... Are you talking about _RUNNING_ python scripts? Is that what
                      you mean by "compile" -- you mean execute? Is that what this broken
                      shell script means?

                      "exec" "python" "-O" "$0" "$@"

                      You don't need exec, the double quote on every word breaks it, and
                      passing $0 (which is the shell script itself) to python is sure to
                      break. Try this:

                      #!/bin/sh
                      python -O "$@"

                      Then:

                      $ run_python.sh file.py arg1 arg2 arg3

                      Regards,
                      Jordan

                      Comment

                      • mistral

                        #12
                        Re: Need compile python code


                        MonkeeSage писал(а):
                        mistral wrote:
                        No, something is wrong there. what I need is just compile one python
                        file which will generate html page, with parameters:
                        "exec" "python" "-O" "$0" "$@"

                        just need simple way do this(script is correct), i will not set any
                        patches anywhere, can i do this wrom normal GUI?
                        >
                        Hmmm... Are you talking about _RUNNING_ python scripts? Is that what
                        you mean by "compile" -- you mean execute? Is that what this broken
                        shell script means?
                        >
                        "exec" "python" "-O" "$0" "$@"
                        >
                        You don't need exec, the double quote on every word breaks it, and
                        passing $0 (which is the shell script itself) to python is sure to
                        break. Try this:
                        >
                        #!/bin/sh
                        python -O "$@"
                        >
                        Then:
                        >
                        $ run_python.sh file.py arg1 arg2 arg3
                        >
                        Regards,
                        Jordan
                        -------
                        the html page just encoded within that py script. To get it, i need run
                        this python file.
                        Since i can no work with this command line, i tried via Python IDE
                        interface: I run this IDE, select File Run specify file name, in
                        'Parameters' box type parameters:

                        exec python -O $0 $@

                        and run. I got some file in output - unknown file type, then I renamed
                        it and got something look like a page i need. Dont know is this right
                        way or not, but it provided some result.. (unlike useless command line
                        interface)
                        All this extremelly inconvenient however. This ActivePython wrote in my
                        Registry 243 registry entries..

                        mistral

                        Comment

                        • John Machin

                          #13
                          Re: Need compile python code


                          mistral wrote:
                          <various_others писал(а):
                          There seems to be a rather large communication gap. Consider asking
                          your question in a Russian-speaking Python-related forum, for example:
                          Материалы для изучения Python: синтаксис, работа с данными, функции, ООП, библиотеки, автоматизация, веб-разработка и советы для эффективного обучения.


                          Regards,
                          John

                          Comment

                          • Piet van Oostrum

                            #14
                            Re: Need compile python code

                            >>>>"MonkeeSage " <MonkeeSage@gma il.com(M) wrote:
                            >Mmistral wrote:
                            >>No, something is wrong there. what I need is just compile one python
                            >>file which will generate html page, with parameters:
                            >>"exec" "python" "-O" "$0" "$@"
                            >>>
                            >>just need simple way do this(script is correct), i will not set any
                            >>patches anywhere, can i do this wrom normal GUI?
                            >MHmmm... Are you talking about _RUNNING_ python scripts? Is that what
                            >Myou mean by "compile" -- you mean execute? Is that what this broken
                            >Mshell script means?
                            >M"exec" "python" "-O" "$0" "$@"
                            >MYou don't need exec, the double quote on every word breaks it, and
                            >Mpassing $0 (which is the shell script itself) to python is sure to
                            >Mbreak. Try this:
                            I guess this is a trick to use a python script as a shell script that
                            executes itself. In other words it is both a shell script and a python
                            script and when executed as a shell script then it passes itself to the
                            python interpreter. When executed as a python script the first line is a
                            comment and the second line is a string (equal to 'execpython-O$0$@'), so
                            both are skipped.

                            You can't use that in windows, or maybe there is an equivalent trick.
                            --
                            Piet van Oostrum <piet@cs.uu.n l>
                            URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C 4]
                            Private email: piet@vanoostrum .org

                            Comment

                            • mistral

                              #15
                              Re: Need compile python code


                              Piet van Oostrum писал(а):
                              >>>"MonkeeSag e" <MonkeeSage@gma il.com(M) wrote:
                              >
                              Mmistral wrote:
                              >No, something is wrong there. what I need is just compile one python
                              >file which will generate html page, with parameters:
                              >"exec" "python" "-O" "$0" "$@"
                              >>
                              >just need simple way do this(script is correct), i will not set any
                              >patches anywhere, can i do this wrom normal GUI?
                              >
                              MHmmm... Are you talking about _RUNNING_ python scripts? Is that what
                              Myou mean by "compile" -- you mean execute? Is that what this broken
                              Mshell script means?
                              >
                              M"exec" "python" "-O" "$0" "$@"
                              >
                              MYou don't need exec, the double quote on every word breaks it, and
                              Mpassing $0 (which is the shell script itself) to python is sure to
                              Mbreak. Try this:
                              >
                              I guess this is a trick to use a python script as a shell script that
                              executes itself. In other words it is both a shell script and a python
                              script and when executed as a shell script then it passes itself to the
                              python interpreter. When executed as a python script the first line is a
                              comment and the second line is a string (equal to 'execpython-O$0$@'), so
                              both are skipped.
                              >
                              You can't use that in windows, or maybe there is an equivalent trick.
                              --
                              Piet van Oostrum <piet@cs.uu.n l>
                              URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C 4]
                              Private email: piet@vanoostrum .org
                              -----------

                              anyway, this is a wrong and clumsy way writing of scripts, rather than
                              write clear and correct code comfortable to work.

                              mistral

                              Comment

                              Working...