导致问题的代码是一个脚本
script1.py
,其中包含:subprocess.call(['gksudo','python script2.py'])
当我正常运行脚本时,这个操作很好用,但是一旦它们被打包进PyInstaller中,我不知道如何让这个调用操作起作用。
script1.py
,其中包含:subprocess.call(['gksudo','python script2.py'])
当我正常运行脚本时,这个操作很好用,但是一旦它们被打包进PyInstaller中,我不知道如何让这个调用操作起作用。
我认为pyinstaller无法独立处理这种打包方式,至少我没有成功地配置它。我的应用程序还比较大,其中一些调用执行了
subprocess.Popen('python ' ... )
的命令。我最终让它正常工作的方法是:
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
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 )
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={})
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)
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,则我认为不需要像这样的任何操作,前三个步骤就足够了。