How can I make a Python script standalone executable to run without ANY dependency?

后端 未结 19 2751
眼角桃花
眼角桃花 2020-11-21 04:51

I\'m building a Python application and don\'t want to force my clients to install Python and modules.

So, is there a way to compile a Python script to be a standalone

相关标签:
19条回答
  • 2020-11-21 05:22

    You can use py2exe as already answered and use Cython to convert your key .py files in .pyc, C compiled files, like .dll in Windows and .so on Linux.

    It is much harder to revert than common .pyo and .pyc files (and also gain in performance!).

    0 讨论(0)
  • 2020-11-21 05:22

    I like PyInstaller - especially the "windowed" variant:

    pyinstaller --onefile --windowed myscript.py
    

    It will create one single *.exe file in a distination/folder.

    0 讨论(0)
  • 2020-11-21 05:24

    You can find the list of distribution utilities listed at Distribution Utilities.

    I use bbfreeze and it has been working very well (yet to have Python 3 support though).

    0 讨论(0)
  • 2020-11-21 05:25

    You can use PyInstaller to package Python programs as standalone executables. It works on Windows, Linux, and Mac.

    PyInstaller Quickstart

    Install PyInstaller from PyPI:

    pip install pyinstaller
    

    Go to your program’s directory and run:

    pyinstaller yourprogram.py
    

    This will generate the bundle in a subdirectory called dist.

    For a more detailed walkthrough, see the manual.

    0 讨论(0)
  • 2020-11-21 05:31

    py2exe will make the EXE file you want, but you need to have the same version of MSVCR90.dll on the machine you're going to use your new EXE file.

    See Tutorial for more information.

    0 讨论(0)
  • 2020-11-21 05:32

    I also recommend PyInstaller for better backward compatibility such as Python 2.3 - 2.7.

    For py2exe, you have to have Python 2.6.

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