安装compileall模块
pip install compileall2
apt-get install rename
# 源码编译
假设项目目录是 demo,进到demo目录下,以下所有命令都是而在demo目录下操作
1.python -O -m compileall . 编译
编译后的执行文件在 demo/__pycache__ 目录下,具体名称与使用的python版本有关
2. find . -name '*.pyc' -exec rename 's/.cpython-36.opt-1//' {} \; (改名,此处名称与实际python版本相关,我这版本是3.6)
3. find . -name '*.pyc' -execdir mv {} .. \; # 移动pyc文件
4. find . -name '__pycache__' -exec rmdir {} \; # 删除目录
5. find . -name "*.py" -type f -print -exec rm -rf {} \; 删除py文件