.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
本文介绍了如何在Python中使用mpy_compile编译单个文件,compileall编译多个文件,以及如何利用Cython扩展和PyArmor进行代码加密。还涵盖了设置.pyd文件和使用setup.py构建项目的步骤。
583

被折叠的 条评论
为什么被折叠?



