使用 pyinstaller 时出错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff [英] Error when using pyinstaller: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff
问题描述
我在使用 pyinstaller 编译 PyQt 代码时遇到问题.
I have an issue when i compile a PyQt code with pyinstaller.
我用这一行编译:
c:\Anaconda3\Scripts\pyinstaller.exe -y -F --distpath="." MyQt.py
然后我收到此错误消息:
then I get this error message:
File "c:\anaconda36bis\lib\site-packages\PyInstaller\hooks\hook-zmq.py", line
18, in <module>
hiddenimports.extend(collect_submodules('zmq.backend'))
File "c:\anaconda36bis\lib\site-packages\PyInstaller\utils\hooks\__init__.py",
line 619, in collect_submodules
repr(pkg_dir), package))
File "c:\anaconda36bis\lib\site-packages\PyInstaller\utils\hooks\__init__.py",
line 90, in exec_statement
return __exec_python_cmd(cmd)
File "c:\anaconda36bis\lib\site-packages\PyInstaller\utils\hooks\__init__.py",
line 77, in __exec_python_cmd
txt = exec_python(*cmd, env=pp_env)
File "c:\anaconda36bis\lib\site-packages\PyInstaller\compat.py", line 562, in
exec_python
return exec_command(*cmdargs, **kwargs)
File "c:\anaconda36bis\lib\site-packages\PyInstaller\compat.py", line 369, in
exec_command
out = out.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 152: invali
d start byte
我不清楚错误消息,我不明白为什么会发生这种情况.
The error message is not clear to me and I don't understand why this happens.
pyinstaller 是否有可能尝试使用不兼容的模块?我在我的脚本中使用这些:
Is it possible that pyinstaller try to use a module which is not compatible? I use these in my script:
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
# from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import sys
import numpy as np
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from scipy.ndimage import imread
from scipy.ndimage.morphology import binary_dilation
from scipy.optimize import curve_fit, leastsq
更新
控制台中打印的问题直接出现在
update
the issue printed in the console come directly after
142859 INFO: Loading module hook "hook-zmq.py"...
所以这应该意味着错误来自 zmq?
So it should mean that the error is coming from zmq?
推荐答案
我在另一个论坛上找到了答案.我更改了 Python\Lib\site-packages\Pyinstaller\compat.py
文件中的行号 369:
I found an answer on another forum.
I change the line number 369 in the Python\Lib\site-packages\Pyinstaller\compat.py
file:
out = out.decode(encoding)
到
out = out.decode(encoding, errors='ignore')
或
out = out.decode(encoding, "replace")
现在我可以毫无问题地编译我的脚本了.我仍然不知道为什么我的问题首先发生,但至少现在可以编译.
Now I can compile my script without any issue. I still don't know why my issue happened in the first place but at least that compiles now.
这篇关于使用 pyinstaller 时出错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!