What are the limitations of distributing .pyc files?

前端 未结 3 811
滥情空心
滥情空心 2020-12-01 18:13

I\'ve started working on a commercial application in Python, and I\'m weighing my options for how to distribute the application.

Aside from the obvious (distribute s

相关标签:
3条回答
  • 2020-12-01 18:51

    You certainly could distribute the .pyc files only. As Cat mentioned, no it would not be compatible with different major version of Python. It might prevent some people from viewing the source code, but the .pyc files are very easy to decompile. Basically if you can compile it, you can decompile it.

    You could use a binary packager like py2exe / py2app / freeze. I've never tried them but someone could still decompile them if they wanted to.

    0 讨论(0)
  • 2020-12-01 19:07

    As Cat said, pyc files are not cross version safe. Though what you're trying to hide from the users determines what you need to do.

    As for source code, there is no good way to hide Python source code in a distributed application. If you just trying to hide specific details you could pack those into a C extension -- which would be much harder to decompile.

    So if you're worried about code use, put a license attached to the code for no-use or translate the sections you don't want stolen to a compiled language. If you just want code to not be obviously Python, you can create a binary executable that wraps the Python code (though doesn't hide the actual details if someone extracts them from the file).

    0 讨论(0)
  • 2020-12-01 19:13

    For example, would a file generated with Python 3.1.5 be compatible with Python 3.2.x?

    No.

    Or would a .pyc file generated with Python 2.7.3 be compatible with a Python 3.x release?

    Doubly no.

    I'm considering distributing just the .pyc files without their corresponding .py sources.

    Python bytecode is high-level and trivially decompilable.

    0 讨论(0)
提交回复
热议问题