Cannot run a specific .pyc file

前端 未结 2 1466
借酒劲吻你
借酒劲吻你 2021-02-09 06:04

After compiling a in unix-working python file using

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

I get the .pyc file in the same directo

相关标签:
2条回答
  • 2021-02-09 06:41

    Compiling a python file does not produce an executable, unlike C. You have to interpret the compiled Python code with the Python interpreter.

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

    The only change compiled Python code has is that it takes slightly less time to load. The Python interpreter already compiles code when it is loaded, and that doesn't take very long at all.

    0 讨论(0)
  • 2021-02-09 06:49

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

    python -c "import server"
    python -m server
    
    0 讨论(0)
提交回复
热议问题