deploying python applications

前端 未结 5 1367
盖世英雄少女心
盖世英雄少女心 2021-01-02 00:45

Is it possible to deploy python applications such that you don\'t release the source code and you don\'t have to be sure the customer has python installed?

I\'m thin

5条回答
  •  被撕碎了的回忆
    2021-01-02 01:26

    I am surprised no one mentioned this before now, but Cython seems like a viable solution to this problem. It will take your Python code and transpile it into CPython compatible C code. You also get a small speed boost (~25% last I checked) since it will be compiled to native machine code instead of just Python byte code. You still need to be sure the user has Python installed (either by making it a pre-requisite pushed off onto the user to deal with, or bundling it as part of the installer process). Also, you do need to have at least one small part of your application in pure Python: the hook into the main function.

    So you would need something basic like this:

    import cython_compiled_module
    
    if __name__ == '__main__':
        cython_compiled_module.main()
    

    But this effectively leaks no implementation details. I think using Cython should meet the criteria in the question, but it also introduces the added complexity of compiling in C, which loses some of Python's easy cross-platform nature. Whether that is worth it or not is up to you.

    As others stated, even the resulting compiled C code could be decompiled with a little effort, but it is likely much more close to the type of obfuscation you were initially hoping for.

提交回复
热议问题