首页 > 技术文章 > python编译模块为2禁制

diege 2014-09-28 15:56 原文

编译模块为2禁制
yum -y install python26-setuptools
easy_install -U setuptools
# cd /usr/lib64/python2.6
# easy_install py_compile

python -O -m py_compile file.py

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


也可以写一个脚本来实现:
Python代码
import py_compile

py_compile.compile("file_path")

推荐阅读