首页 > 解决方案 > 如何永远隐藏 Python 中的源代码?

问题描述

有没有办法确定我的源代码真的被隐藏了?我使用 pyinstaller 创建 exe,以便我的朋友可以在没有 python 的情况下使用我的应用程序。我的想法是使用 pyinstaller 中的所有文件创建一个 USB 磁盘,它们被锁定以防止读取代码。此应用程序只能通过桌面上的快捷方式启动。但是我没有找到解决方法。有人知道一种功能性的方法来锁定我的 python 应用程序而无需阅读代码以便仅使用它吗?

标签: pythonlockingpyinstaller

解决方案


您可以使用py_compile将代码编译为“pyc”格式

import py_compile
py_compile.compile(filename, compiled_filename, optimize=2)

请注意:
您需要使用相同版本的 python 和所有用于启动此编译文件的库。
对于加载文件(例如:open("text.txt", "r")),您需要指定所有树(例如:open("C:/Users/Me/Desktop/MyProgram/test.txt", " r"))


推荐阅读