PyQt5系列教程(十二)pyinstaller打包exe时subprocess无效的解决方法
2017-03-12 20:04
701 查看
软硬件环境
Windows 10Python 3.5.2
PyQt5
pyinstaller
前言
前面一篇博文PyQt5系列教程(十)pyinstaller打包exe已经介绍过如何使用pyinstaller打包exe,最近在打包包含subprocess.Popen时发现,加上参数—noconsole时产生的exe文件在运行的时候,进程并没有运行。经过一番google,问题得以解决,现将解决方法记录一下,形成此文。subprocess的使用
我这里需要利用subprocess.Popen创建一个进程去执行一个命令行操作,mProcess = subprocess.Popen(cmd,stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True)
pyinstaller打包操作命令如下
pyinstaller -F --noconsole --clean --distpath release bin\\troutling
打包后生成的exe,可以运行,不过查看进程并没有如预期正确地工作。
解决方法
在创建进程时,加上startupinfo参数,如下si = subprocess.STARTUPINFO() si.dwFlags |= subprocess.STARTF_USESHOWWINDOW mProcess = subprocess.Popen(cmd,stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True,startupinfo=si)
问题完美解决,具体可以参考下参考资料
参考资料
1 https://github.com/pyinstaller/pyinstaller/wiki/Recipe-subprocess2 https://github.com/djstava/troutling
相关文章推荐
- PyQt5系列教程(十)pyinstaller打包exe
- 使用pyinstaller打包,subprocess报“句柄无效”错误的解决方法
- 使用pyinstaller打包成exe之后运行闪退,调试后报出 Unable to acquire Oracle environment handle错误解决方法
- PyQt5系列教程(三)用py2exe进行程序打包
- 用cocos2dx打包时出现“make.exe: *** No rule to make target ”的解决方法
- 关于使用pyinstaller 打包带有matplotlib 等出现UnicodeDecodeError解决方法
- PyInstaller(windows开发,打包python软件为exe)使用教程
- Discuz!教程之论坛设置过滤词无效的解决方法
- 关于解决pyinstaller2.1将.py打包成exe文件在中文目录下不能执行的问题
- pyinstaller 打包程序 出现错误的解决方法
- 【REACT NATIVE 系列教程之十】真机运行报错COMMAND /BIN/SH FAILED WITH EXIT CODE 1 的解决方法
- 关于使用pyinstaller 打包带有matplotlib 等出现UnicodeDecodeError解决方法
- C# ASP.NET Webservice调用外部exe无效的解决方法
- node-webkit打包成exe文件被360误报木马的解决方法
- 用cocos2dx打包时出现“make.exe: *** No rule to make target ”的解决方法
- 文件操作乱码解决及java程序打包EXE全教程
- node-webkit打包成exe文件被360误报木马的解决方法
- 关于VS2012 (error MSB6001 “cmd.exe”的命令行开关无效。路径的形式不合法)错误的一种解决方法
- 升级win10 wuauclt.exe /updatenow无效、没反应的解决方法
- UE4打包的exe运行未响应解决方法