我无法让 PyInstaller 在一台 PC(PC-Good)上生成的 exe 在另一台(PC-Bad)上工作。
- 该 exe 在 PC-Good 上创建,并在 PC-Good 上按预期执行
- 两台电脑都运行 Windows 10
- 调用大多数 matplotlib.pyplot 方法(例如 subplots() 或 plot())时,PC-Bad 出现问题
- 即使 matplotlib 处于非交互模式,问题仍然存在
- 失败时不报告错误。exe简单地退出
- 即使 matplotlib 详细程度更改为“调试”
- 即使在 try-exception 中捕获了问题陈述
请参阅下面的代码:
print('Start')
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
print("Import of matplotlib & pyplot successful")
plt.set_loglevel("debug")
x = [0, 1, 2, 3, 4]
y = [4, 3, 2, 1, 0]
print('list creation successful')
try:
fig, ax = plt.subplots(1, 1, figsize=(12, 6))
except Exception as exception:
print(exception.__class__.__name__ + ": ", + exception.message)
finally:
print('run subplots() successful')
plt.scatter(x, y)
print('plot creation successful')
plt.savefig('saved_plot.png')
print('code complete')
PC-Good 上的输出:
Start
C:\tools\miniconda3\envs\bcht\lib\site-packages\PyInstaller\loader\pyimod03_importers.py:623: MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
exec(bytecode, module.__dict__)
Import of matplotlib & pyplot successful
list creation successful
run subplots() successful
plot creation successful
DEBUG:matplotlib.font_manager:findfont: ...
(and many more matplotlib DEBUG messages)
code complete
PC-Bad 上的输出:
Start
C:\tools\miniconda3\envs\bcht\lib\site-packages\PyInstaller\loader\pyimod03_importers.py:623: MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
Import of matplotlib & pyplot successful
list creation successful
因为我没有得到错误输出,所以我很不知道下一步该去哪里。Matplotlib 文档没有提供任何关于获取更精细的调试消息的提示,例如绘图或子图。有没有其他人观察到这样的问题或知道修复?或者有谁知道是否有办法让 Matplotlib 告诉我更多信息?