Those of you who know Python know that Pyinstaller can package.py files into.exe files that can be executed on Windows, but it can’t do that if you don’t want someone to decompile the source code, you can look at.pdy files.

PYD

Pyc is a binary file generated by the Python compiler. It is fast to load. Pyo is an optimized compiled binary that can be generated using python -o file.py. Pyd is a dynamically linked library for Python, written in other languages.

Can. Pyd be decompiled?

Pyd is made up of C or C++ compilations. Whether it is completely undecompilable or not, I believe, is impossible. It just makes decompilation more difficult.

packaging

You need to install Cython and PyInstaller as dependencies. Docs

  • Write the primary agent tomain_code.pyIn the document, it is recommended to provide entry functionsmain()
  • writebuild.pyAgent and type the following:
    from distutils.core import setup
    
    from Cython.Build import cythonize
    
    setup(
        name="Write whatever you want.",
        ext_modules=cythonize([
            "main_code.py".# Your main code encapsulates the filename]))Copy the code
  • performpython3 build.py build_ext --inplacegenerate.pydfile
  • Rename generated.pydmain_code.pyd
  • Create an execution script filerun.pyAnd type the following:
    from main_code import *
    
    if __name__ == '__main__':
    
        main()
    Copy the code

    At this point you can try to modifymain_code.pyChange the name to something else and runrun.pyThe file you will find works fine.

  • performpyinstaller -D -i xxx.ico -w run.py

Eventually you will find that the main logic for.pyc is missing from your code.

instructions

To use -d instead of -f for packaging?

It is too slow after generating a unique.exe file, of course I only recommend that you use any custom way to compile the effect you want.




Give it a thumbs up