Python编译pyc文件

没落的情绪 2021-02-05 PM 733℃ 0条

一、编译生成pyc
1、单个文件

import py_compile
py_compile.compile(r"Path/a.py")

2、多个文件

import compileall
compileall.compile_dir(r"Path")

3、直接命令运行

python -m py_compile test.py
python -O -m py_compile test.py

-O 优化成字节码
-m 表示吧后面的模块当成脚本运行
-OO 表示优化的同时删掉文档字符串
二、运行Pyc

python test.pyc
标签: Python

非特殊说明,本博所有文章均为博主原创。

评论啦~