pyinstaller打包exe后报fatal error return -1

引起这个问题的原因,我在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)

解析这个错INTEL MKL ERROR: dlopen(/Users/baiminchen/opt/anaconda3/lib/libmkl_core.1.dylib, 0x0009): tried: '/Users/baiminchen/opt/anaconda3/lib/libmkl_core.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/baiminchen/opt/anaconda3/lib/libmkl_core.1.dylib' (no such file), '/Users/baiminchen/opt/anaconda3/lib/libmkl_core.1.dylib' (no such file). Intel MKL FATAL ERROR: Cannot load libmkl_core.1.dylib. Traceback (most recent call last): File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/isolated/_parent.py", line 373, in call return isolated.call(function, *args, **kwargs) File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/isolated/_parent.py", line 302, in call ok, output = loads(b64decode(self._read_handle.readline())) EOFError: EOF read where object expected During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/baiminchen/opt/anaconda3/bin/pyinstaller", line 8, in <module> sys.exit(_console_script_run()) File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/__main__.py", line 194, in _console_script_run run() File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/__main__.py", line 180, in run run_build(pyi_config, spec_file, **vars(args)) File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/__main__.py", line 61, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 971, in main build(specfile, distpath, workpath, clean_build) File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 893, in build exec(code, spec_namespace) File "/Users/baiminchen/Desktop/database of xinstitute/main.spec", line 7, in <module> a = Analysis( File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 378, in __init__ self.hookspath += discover_hook_directories() File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/isolated/_parent.py", line 404, in wrapped return call(function, *args, **kwargs) File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/isolated/_parent.py", line 373, in call return isolated.call(function, *args, **kwargs) File "/Users/baiminchen/opt/anaconda3/lib/python3.9/site-packages/PyInstaller/isolated/_parent.py", line 244, in __exit__ self._write_handle.flush() BrokenPipeError: [Errno 32] Broken pipe
02-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值