Cannot start specific .pyc file

After compiling in a unix working python file using

import py_compile py_compile.compile('server.py') 

I get the .pyc file in the same directory, but when I try to run this file using "./server.pyc" in putty, all I get is the scrambled code as a result, and nothing really happens.

So the question is, how to compile the .py file in the .pyc file correctly and how to run this .pyc file?

ps: I checked the compilation and launch of the base script that worked.

+4
source share
2 answers

Compiling a python file does not create an executable, unlike C. You must interpret the compiled Python code using the Python interpreter.

 $ python >>> import py_compile >>> py_compile.compile('server.py') >>> ^D $ python ./server.pyc 

The only compiled Python code with the changes is that it takes a little less time to load. The Python interpreter already compiles the code when it is loaded, and it does not take a very long time.

+9
source

Run the first command to create the server.pyc file. Then the second command can start the server.pyc module. The -c and -m option options are described in python docs.

 python -c "import server" python -m server 
+4
source

Source: https://habr.com/ru/post/1440949/


All Articles