1.python编译py文件成pyc文件
命令行
python -m py_compile *.py
//其中*.py为所编译文件的路径
python shell 脚本
import py_compile
py_compile.compile(r'*.py')
2.python编译py文件成pyo文件
命令行
python -O -m py_compile *.py
其他选项可以在命令行输入 python -h 来查看
3.什么是pyc文件
pyc文件是py文件经过编译后生成的二进制字节码
4.什么是pyo文件
pyo文件是py文件经过优化编译后生成的二进制字节码
5.python批量编译一个目录及子目录下的py文件成pyc文件
命令行
python -m compileall path
//其中path为目录名
python shell脚本
import compileall
compileall.compile_dir(r'path')