py加密

发布时间 2024-01-02 16:12:38作者: 一枚码农

.pyc

1.单个文件:
python -m py_compile file.py

其中的 -m 相当于脚本中的import,这里的-m py_compile 相当于import py_compile

脚本:
Code:
import py_compile
py_compile.compile('path') //path是包括.py文件名的路径


2.多个文件
python -m compileall /root/src/

脚本:
Code:
import compileall
compileall.compile_dir(r'H:\game')

(Cython).pyd

pip install Cython

cat setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(
   ext_modules=cythonize("hello.py")
)

python setup.py build_ext --inplace

需要import到py文件中执行

pyarmor加密

pip install pyarmor

pyarmor gen foo.py
这个命令会生成一个加密脚本 dist/foo.py ,这也是一个正常的 Python 脚本,可以直接使用 Python 解释器执行:
python dist/foo.py

文档链接:https://pyarmor.readthedocs.io/zh/stable/tutorial/getting-started.html