pyinstaller打包exe后报fatal error return -1
来源:互联网 发布:买断软件源码 编辑:程序博客网 时间:2024/05/18 00:21
引起这个问题的原因,我在stackoverflow中找到了,如果调用控制台输入,输出,但是将python脚本打包成exe(非控制台 --window或--noconsole)的话,会出现这个问题。
解决方案是需要将输入、输出重定向。
参见stackoverflow
I had a similar issue with a root cause involving subprocess.Popen, if you are not using this function (or something similar) then this answer is unlikely to be helpful.
I was having a similar issue trying to build my .exe with pyinstaller. I was using the --noconsole flag as well as the --onefile flag with pyinstaller and was getting the "Fatal Error!" message " returned -1" whenever I tried to execute the resulting .exe file. My .exe would build work with just the --onefile flag but any combination using the --noconsole flag would return the error, leading me to believe it was the source of my issue.
After a little digging I tracked down this answer:
Python subprocess.call() fails when using pythonw.exe
Which seemed to indicate the issue was using pipes when using subprocess.Popen with pythonw.exe instead of python.exe. It seemed logical to me that pyinstaller with the --noconsole flag would use pythonw.exe instead of python.exe when building the .exe leading me to believe this could apply to my issue.
To test this I refactored by code to output the results of my Subprocess.Popen call to a file, then read in and deleted the file. This solved my "Fatal Error!" issue and everything else proceeded to work fine.
Original:
process = subprocess.Popen('cmd /c whoami', stdout=subprocess.PIPE)user = process.communicate()[0].decode('ascii').strip()
Refactored:
pro = subprocess.Popen('cmd /c whoami > "{0}"'.format(file_name))pro.wait()with open(file_name, 'rt') as file: user = file.read().strip()os.remove(file_name)
- pyinstaller打包exe后报fatal error return -1
- pyinstaller生成的exe运行报错 Intel MKL FATAL ERROR: Cannot load mkl_mc3.dll or mkl_def.dll
- pyinstaller打包exe--requests模块打包后无法运行
- pyinstaller打包exe错误
- pyinstaller打包exe文件
- Pyinstaller打包exe
- 使用Pyinstaller打包exe
- pyinstaller打包exe---打包实践
- pyinstaller打包python成exe
- python打包exe之pyinstaller
- pyinstaller.exe打包的总结
- pyinstaller打包exe---requests模块打包后无法运行问题记录
- Pyinstaller打包matplotlib error总结
- Pyinstaller打包运行exe报错 No module named matplotlib.backends.backend_tkagg
- pyinstaller 打包生成.exe 可执行文件报错 “IndexError: tuple index out of range”
- pyinstaller打包后的exe运行怎么去掉弹出的dos窗口
- pyinstaller--将python打包成exe
- 使用pyinstaller打包python为exe文件
- 深究AngularJS——$sce的使用
- 看到街头卖艺的,小孩子会说哇这个人好厉害,大人会说,他就是练这个的,一句话把自己撇的干干净净
- 看到街头卖艺的,小孩子会说哇这个人好厉害,大人会说,他就是练这个的,一句话把自己撇的干干净净
- eclipse的web project 的src目录问题
- 配图快速入门及地图性能优化(1)
- pyinstaller打包exe后报fatal error return -1
- 冲突解决策略是定义一个序列F(i)=ri,其中r0=0且r1,r2……rN是前N个整数的随机排列(每个整数恰好出现一次)
- windows下消息机制
- Selenium - Best practices
- andriod studio 快捷键
- android studio单元测试 无法进入网络请求的回调
- c++ 赋值操作符
- 通俗易懂之epoll--转自”知乎“
- Unity3D 游戏引擎之C#使用Socket与HTTP连接服务器传输数据包