我想将一组代码转换为包,这样用户就看不到代码,但他们可以运行该文件

问题描述 投票:0回答:1

我有点困惑如何在 python 中执行此操作。在我的代码中,我希望用户能够运行 main.py 文件,而无需看到该文件的代码。

python package software-design
1个回答
0
投票

使用 PyInstaller 库(文档 - https://pyinstaller.org/en/stable)打包您的代码,您可以在 Windows 下使用以下命令 -

pyinstaller sourcecode.py --onefile

虽然这不会保留源代码,但它会创建编译后的 python 脚本(.pyc 文件),可以对其进行解码以显示源代码。混淆的一种方法是使用 cython 编译一些代码,将 python 转换为 C,并将 C 编译为机器语言。

© www.soinside.com 2019 - 2024. All rights reserved.