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

后端 未结 19 3111
眼角桃花
眼角桃花 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:43

    I would like to compile some useful information about creating standalone files on Windows using Python 2.7.

    I have used py2exe and it works, but I had some problems.

    • It has shown some problems for creating single files in Windows 64 bits: Using bundle_files = 1 with py2exe is not working;

    • It is necessary to create a setup.py file for it to work. http://www.py2exe.org/index.cgi/Tutorial#Step2;

    • I have had problems with dependencies that you have to solve by importing packages in the setup file;

    • I was not able to make it work together with PyQt.

    This last reason made me try PyInstaller http://www.pyinstaller.org/.

    In my opinion, it is much better because:

    • It is easier to use.

    I suggest creating a .bat file with the following lines for example (pyinstaller.exe must be in in the Windows path):

    pyinstaller.exe --onefile MyCode.py
    
    • You can create a single file, among other options (https://pyinstaller.readthedocs.io/en/stable/usage.html#options).

    • I had only one problem using PyInstaller and multiprocessing package that was solved by using this recipe: https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing.

    So, I think that, at least for python 2.7, a better and simpler option is PyInstaller.

提交回复
热议问题