隐藏/保护 Python 代码 [英] Hide/protect Python code

查看:26
本文介绍了隐藏/保护 Python 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写代码(用于 GUI 的 Python 和 wxpython),它将在 Raspberry PI 上的 Debian 操作系统上运行.我想保护/隐藏源代码.有什么办法吗?可能是py2exe,或者将其转换为库或其他东西?

I am writing code (Python and wxpython for GUI) which will run on Debian OS on Raspberry PI. I want to protect/hide the source code. Is there any way to do it? Probably py2exe, or converting it to a library or something else?

推荐答案

如果您希望其他人能够执行但不能读取或修改源代码(.py.pyw).

The compiled code (.pyc files) can be used if you wish for others to be able to execute but not to read or modify the source code (.py, .pyw).

简单地说:

  1. 运行您的应用程序
  2. 然后将所有相关的 .pyc 文件复制到另一个文件夹中,您应该能够
  3. 从新位置运行这一切

只要所有适当的模块仍然能够加载,一切都会正常进行.这将要求 python 的版本相同(不能使用 python 2.7 运行 python 2.4 中的 .pyc 文件,反之亦然)

So long as all the appropriate modules are still able to be loaded, everything will work. This will require the version of python to be the same (can't run .pyc files from python 2.4 with python 2.7 and vice-versa)

另一件要知道的事情是字符串将被保留.如果您担心其他人可以看到什么,您应该在一个好的文本编辑器(我使用 vim)中打开它们并检查内容.

The other thing to know is that strings will be preserved. You should open them up in a good text editor (I use vim) and inspect the content if you are worried about what others can see.

py2exe 当然是另一个例子,但此时你失去了跨平台代码的能力——如果你的应用程序是用于 Raspberry Pi——那将无法工作.

py2exe is of course another example, but you lose the ability to have cross-platform code at that point -- and if your application is for the Raspberry Pi -- that won't work.

由于您没有提供有关您打算如何运行代码的其他信息,因此不清楚源是模块还是打算直接运行.您应该阅读这篇文章 了解更多.

Since you provided no other information about how you intend to run the code, it's not clear if the source will be a module or intended to be run directly. You should read this post to learn more.

这篇关于隐藏/保护 Python 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆