问题
I'm using tkinter and pyinstaller/py2exe (either one would be fine), to create an executable as a single file from my python script. I can create the executable, and it runs as desired when not using the bundle option with py2exe or -F option with pyinstaller. I'm running third party python scripts within my code with os.system(), and can simply place these scripts in the 'dist' dir after it is created in order for it to work. The command has several parameters: input file, output file, number of threads..etc, so I'm unsure how to add this into my code using import. Unfortunately, this is on Windows, so some colleagues can use the GUI, and would like to have the single executable to distribute.
**EDIT:**I can get it to bundle into a single executable, and provide the scripts along with the exe. The issue still however, is with os.system("python script.py -1 inputfile -n numbthreads -o outputfile..")
when running the third party scripts within my code. I had a colleague test the executable with the scripts provided with it, however at this point they need to have python installed, which is unacceptable since there will be multiple users.
回答1:
After a couple of days of some tests, I was able to figure out how to work around this problem. Instead of os.system
, I am using subprocess.call("script.py arg1 arg2 ..., shell=True)
for each script I need to run. Also, I used chmod +x
(in linux) before transferring the scripts to windows to ensure they're an executable (someone can hopefully tell me if this was really necessary). Then without having to install python a colleague was able to run the program, after I compiled it as a single file with pyInstaller. I was also able to do the same thing with blast executables (where the user did not have to install blast locally - if the exe also accompanied the distribution of the script). This avoided having to call bipython ncbiblastncommandline and the install.
来源:https://stackoverflow.com/questions/38603480/pyinstaller-py2exe-include-os-system-call-with-third-party-scripts-in-single-f