对python源码进行编译,加密python脚本
对python源码进行编译
1.生成.pyc文件
import py_compile
py_compile.compile('hello.py')
2.优化源码文件
python -O -m py_compile 1.py
生成.pyo文件
例子:
1 [root@lvs-master tool]# python3 2 Python 3.5.6 (default, May 3 2019, 01:52:28) 3 [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux 4 Type "help", "copyright", "credits" or "license" for more information. 5 >>> import py_compile 6 >>> py_compile.compile('test_conn_linux.py') 7 '__pycache__/test_conn_linux.cpython-35.pyc' 8 >>> 9 >>> exit 10 Use exit() or Ctrl-D (i.e. EOF) to exit 11 12 #执行部分 13 [root@lvs-master __pycache__]# python3 test_conn_linux.cpython-35.pyc 14 序号:0 选择对象:172.16.132.4 15 序号:1 选择对象:192.168.1.111 16 序号:2 选择对象:47.106.169.222 17 序号:3 选择对象:172.16.132.3 18 请输入序号(Q|q退出)