将多个脚本打包成PyInstaller

6
我将使用PyInstaller将两个脚本合并成一个可执行文件,其中一个脚本调用另一个脚本。我遇到的问题是我无法弄清楚如何捆绑这两个脚本并仍然让它们相互引用:
导致问题的代码是一个脚本script1.py,其中包含:
subprocess.call(['gksudo','python script2.py'])

当我正常运行脚本时,这个操作很好用,但是一旦它们被打包进PyInstaller中,我不知道如何让这个调用操作起作用。


请查看多包捆绑以获取更多信息。 - betontalpfa
1个回答

2

我认为pyinstaller无法独立处理这种打包方式,至少我没有成功地配置它。我的应用程序还比较大,其中一些调用执行了

subprocess.Popen('python ' ... )

的命令。我最终让它正常工作的方法是:

  1. Modify your subprocess calls to a different python, like subprocess.call(['gksudo','./python script2.py']). Create two separate analysis, one for the entry point, and one for the rest of the scripts, in your case:

    a1 - analysis of script1.py a2 - analysis of script2.py

  2. Create the exe only from the entry point scripts:

    pyz = PYZ(a1.pure)
    exe = EXE(pyz,
      a1.scripts,
      exclude_binaries=1,
      name={name here},
      debug=False,
      strip=False,
      upx=True,
      console=1 )
    
  3. Collect from all scripts

        coll = COLLECT( exe,
           a1.binaries,
           a1.zipfiles,
           a1.datas,
           a2.binaries,
           a2.zipfiles,
           a2.datas,
       python_tree, 
           *additional_trees,
           strip=False,
           upx=True,
           name={})
    
  4. Copy python in your distribution at location that was specified in all the subprocess calls with any additional requirements that were not found by pyinstaller (i had a few like matplotlib, pylab etc)

  5. Create a start script that first changes any required enviromental variables to point to your package and then start the app. In my case what was needed was, from calling directory:

     export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
     export LD_RUN_PATH=`pwd`:$LD_RUN_PATH
    

如果我想要应用程序在没有安装Python的计算机上运行,或者如果它们已经安装了Python,确保应用程序仍然使用分发包中的所有库而不是任何本地库,则需要执行所有这些操作。如果在您的情况下目标计算机已经安装了Python,则我认为不需要像这样的任何操作,前三个步骤就足够了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接