PyInstaller/Py2exe-在单个文件编译中包含带有第三方脚本的os.system调用 [英] PyInstaller/Py2exe - include os.system call with third party scripts in single file compilation

查看:43
本文介绍了PyInstaller/Py2exe-在单个文件编译中包含带有第三方脚本的os.system调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用tkinter和pyinstaller/py2exe(两者都可以)从我的python脚本创建为单个文件的可执行文件.我可以创建可执行文件,并且在不将py2exe的bundle选项和pyinstaller的-F选项一起使用时,它可以根据需要运行.我正在使用os.system()在我的代码中运行第三方python脚本,并且可以在创建后将这些脚本简单地放置在"dist"目录中以使其正常工作.该命令有几个参数:输入文件,输出文件,线程数..etc,所以我不确定如何使用import将其添加到我的代码中.不幸的是,这是在Windows上,因此某些同事可以使用GUI,并希望分发单个可执行文件.

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.

****我可以将其捆绑到一个可执行文件中,并与exe一起提供脚本.但是,在我的代码中运行第三方脚本时, os.system("python script.py -1 inputfile -n numbthreads -o outputfile ..")仍然是问题.我有一位同事用随附的脚本测试了可执行文件,但是此时他们需要安装python,这是不可接受的,因为会有多个用户.

****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.

推荐答案

经过几天的测试,我能够弄清楚如何解决此问题.我要为每个需要运行的脚本使用 subprocess.call("script.py arg1 arg2 ...,shell = True),而不是 os.system .,在将脚本传输到Windows之前,我使用了 chmod + x (在Linux中)以确保它们是可执行文件(有人希望可以告诉我这是否确实必要),然后不必安装python a在我使用pyInstaller将其编译为单个文件后,同事能够运行该程序.我还可以对blast可执行文件执行相同的操作(用户无需在本地安装blast-如果exe也随发行版一起提供)脚本).这样就不必调用bipython ncbiblastncommandline和安装程序.

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.

这篇关于PyInstaller/Py2exe-在单个文件编译中包含带有第三方脚本的os.system调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆