Compiling python pyo files










1















I have an old c++/python project that includes a python zip file "python27.zip". This zip file contains pyo optimized files.

I am trying to update python from 2.7 to the latest 3.7.1 (also updated the *.so lib file)

I did the next steps:



./configure --enable-shared --prefix=~/python-3.7.1/dist
make
sudo make install


I see that I have ~/python-3.7.1/dist/lib/python3.7 and it's structure is close to that I have in my old 2.7 zip.
Next I try to compile all the folder into pyo like:



python3.7 -O -m compileall .


It tells me that it requires Lib and Include (the headers) so I copied those 2 folders in that location too.

Doing python3.7 -O -m compileall . again inside dist/lib/python3.7 shows me



Listing './Lib/site-packages'...
Listing './Lib/sqlite3'...
....


and some errors like:



Compiling './Lib/test/badsyntax_future10.py'...
*** File "./Lib/test/badsyntax_future10.py", line 3
from __future__ import print_function
^
SyntaxError: from __future__ imports must occur at the beginning of the file


I don't see any pyo's inside. Also if I try to do the same against 1 file, like python3.7 -O token.py (no errors) and also no pyo inside.

Don't judge me strict, I agree that I can be wrong in understanding this compilation process.










share|improve this question


























    1















    I have an old c++/python project that includes a python zip file "python27.zip". This zip file contains pyo optimized files.

    I am trying to update python from 2.7 to the latest 3.7.1 (also updated the *.so lib file)

    I did the next steps:



    ./configure --enable-shared --prefix=~/python-3.7.1/dist
    make
    sudo make install


    I see that I have ~/python-3.7.1/dist/lib/python3.7 and it's structure is close to that I have in my old 2.7 zip.
    Next I try to compile all the folder into pyo like:



    python3.7 -O -m compileall .


    It tells me that it requires Lib and Include (the headers) so I copied those 2 folders in that location too.

    Doing python3.7 -O -m compileall . again inside dist/lib/python3.7 shows me



    Listing './Lib/site-packages'...
    Listing './Lib/sqlite3'...
    ....


    and some errors like:



    Compiling './Lib/test/badsyntax_future10.py'...
    *** File "./Lib/test/badsyntax_future10.py", line 3
    from __future__ import print_function
    ^
    SyntaxError: from __future__ imports must occur at the beginning of the file


    I don't see any pyo's inside. Also if I try to do the same against 1 file, like python3.7 -O token.py (no errors) and also no pyo inside.

    Don't judge me strict, I agree that I can be wrong in understanding this compilation process.










    share|improve this question
























      1












      1








      1








      I have an old c++/python project that includes a python zip file "python27.zip". This zip file contains pyo optimized files.

      I am trying to update python from 2.7 to the latest 3.7.1 (also updated the *.so lib file)

      I did the next steps:



      ./configure --enable-shared --prefix=~/python-3.7.1/dist
      make
      sudo make install


      I see that I have ~/python-3.7.1/dist/lib/python3.7 and it's structure is close to that I have in my old 2.7 zip.
      Next I try to compile all the folder into pyo like:



      python3.7 -O -m compileall .


      It tells me that it requires Lib and Include (the headers) so I copied those 2 folders in that location too.

      Doing python3.7 -O -m compileall . again inside dist/lib/python3.7 shows me



      Listing './Lib/site-packages'...
      Listing './Lib/sqlite3'...
      ....


      and some errors like:



      Compiling './Lib/test/badsyntax_future10.py'...
      *** File "./Lib/test/badsyntax_future10.py", line 3
      from __future__ import print_function
      ^
      SyntaxError: from __future__ imports must occur at the beginning of the file


      I don't see any pyo's inside. Also if I try to do the same against 1 file, like python3.7 -O token.py (no errors) and also no pyo inside.

      Don't judge me strict, I agree that I can be wrong in understanding this compilation process.










      share|improve this question














      I have an old c++/python project that includes a python zip file "python27.zip". This zip file contains pyo optimized files.

      I am trying to update python from 2.7 to the latest 3.7.1 (also updated the *.so lib file)

      I did the next steps:



      ./configure --enable-shared --prefix=~/python-3.7.1/dist
      make
      sudo make install


      I see that I have ~/python-3.7.1/dist/lib/python3.7 and it's structure is close to that I have in my old 2.7 zip.
      Next I try to compile all the folder into pyo like:



      python3.7 -O -m compileall .


      It tells me that it requires Lib and Include (the headers) so I copied those 2 folders in that location too.

      Doing python3.7 -O -m compileall . again inside dist/lib/python3.7 shows me



      Listing './Lib/site-packages'...
      Listing './Lib/sqlite3'...
      ....


      and some errors like:



      Compiling './Lib/test/badsyntax_future10.py'...
      *** File "./Lib/test/badsyntax_future10.py", line 3
      from __future__ import print_function
      ^
      SyntaxError: from __future__ imports must occur at the beginning of the file


      I don't see any pyo's inside. Also if I try to do the same against 1 file, like python3.7 -O token.py (no errors) and also no pyo inside.

      Don't judge me strict, I agree that I can be wrong in understanding this compilation process.







      python-3.x compilation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 12:41









      IgorZIgorZ

      372619




      372619






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I had to create my own tool since I had not found anything suitable for the compilation of all python modules into one location/archive.



          This PY_COMPILE_HELPER is available on the github. It was tested only from ubuntu.



          With this module you can:



          • Set input and output folder for the compilation

          • Output source will have the same structure as the input source

          • Set optimization level for binary files

          • Skip or include test modules

          • Compress compiled files into one archive

          • Clean previously compiled files from the cache

          Usage example:



          $ ./py_compile_helper.py ./Python-3.7.1/Lib ./out -z -c -o2





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319737%2fcompiling-python-pyo-files%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I had to create my own tool since I had not found anything suitable for the compilation of all python modules into one location/archive.



            This PY_COMPILE_HELPER is available on the github. It was tested only from ubuntu.



            With this module you can:



            • Set input and output folder for the compilation

            • Output source will have the same structure as the input source

            • Set optimization level for binary files

            • Skip or include test modules

            • Compress compiled files into one archive

            • Clean previously compiled files from the cache

            Usage example:



            $ ./py_compile_helper.py ./Python-3.7.1/Lib ./out -z -c -o2





            share|improve this answer



























              0














              I had to create my own tool since I had not found anything suitable for the compilation of all python modules into one location/archive.



              This PY_COMPILE_HELPER is available on the github. It was tested only from ubuntu.



              With this module you can:



              • Set input and output folder for the compilation

              • Output source will have the same structure as the input source

              • Set optimization level for binary files

              • Skip or include test modules

              • Compress compiled files into one archive

              • Clean previously compiled files from the cache

              Usage example:



              $ ./py_compile_helper.py ./Python-3.7.1/Lib ./out -z -c -o2





              share|improve this answer

























                0












                0








                0







                I had to create my own tool since I had not found anything suitable for the compilation of all python modules into one location/archive.



                This PY_COMPILE_HELPER is available on the github. It was tested only from ubuntu.



                With this module you can:



                • Set input and output folder for the compilation

                • Output source will have the same structure as the input source

                • Set optimization level for binary files

                • Skip or include test modules

                • Compress compiled files into one archive

                • Clean previously compiled files from the cache

                Usage example:



                $ ./py_compile_helper.py ./Python-3.7.1/Lib ./out -z -c -o2





                share|improve this answer













                I had to create my own tool since I had not found anything suitable for the compilation of all python modules into one location/archive.



                This PY_COMPILE_HELPER is available on the github. It was tested only from ubuntu.



                With this module you can:



                • Set input and output folder for the compilation

                • Output source will have the same structure as the input source

                • Set optimization level for binary files

                • Skip or include test modules

                • Compress compiled files into one archive

                • Clean previously compiled files from the cache

                Usage example:



                $ ./py_compile_helper.py ./Python-3.7.1/Lib ./out -z -c -o2






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 15 at 19:16









                IgorZIgorZ

                372619




                372619





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319737%2fcompiling-python-pyo-files%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    What does pagestruct do in Eviews?

                    Dutch intervention in Lombok and Karangasem

                    Channel Islands