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

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

问题描述

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

解决方案

编译代码( .pyc 文件)可以使用,如果您希望其他人能够执行但不读取或修改源代码( .py .pyw )。



简单地:


  1. 运行您的应用程序

  2. 然后将所有相关的.pyc文件复制到另一个文件夹中,您应该可以

  3. 从新的位置运行所有这些文件

只要所有适当的模块仍然可以加载,一切都会工作。这将需要python的版本是一样的(无法从python 2.4运行.pyc文件与python 2.7,反之亦然)



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



py2exe当然是另一个例子,但是您在这一点上失去了跨平台代码的能力 - 如果您的应用程序是针对Raspberry Pi的,那将无法正常工作。



自您没有提供有关如何打算运行代码的其他信息,不清楚源是否是一个模块或者是要直接运行。您应该阅读这篇文章了解更多。


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?

解决方案

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).

Simply:

  1. run your application
  2. then copy all the relevant .pyc files into another folder and you should be able to
  3. run it all from the new location

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)

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 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天全站免登陆