【发布时间】:2021-12-08 19:20:56
【问题描述】:
尝试导入matplotlib并运行pyinstaller test.py生成的文件会报错:
Fatal Python error: _PyInterpreterState_Get(): no current thread state
Python runtime state: unknown
使用 Pyinstaller 从 .py 文件创建 .exe 文件时,导入任何其他包都可以正常工作,只有 matplotlib 会出现错误。只需使用 import matplotlib.pyplot as plt 创建一个 .py 文件即可重现该错误。
来自 pipdeptree:
pyinstaller==4.5.1
- altgraph [required: Any, installed: 0.17.2]
- pefile [required: >=2017.8.1, installed: 2021.9.3]
- future [required: Any, installed: 0.18.2]
- pyinstaller-hooks-contrib [required: >=2020.6, installed: 2021.4]
- pywin32-ctypes [required: >=0.2.0, installed: 0.2.0]
- setuptools [required: Any, installed: 59.5.0]
- matplotlib [required: >=3, installed: 3.5.0]
- cycler [required: >=0.10, installed: 0.11.0]
- fonttools [required: >=4.22.0, installed: 4.28.3]
- kiwisolver [required: >=1.0.1, installed: 1.3.2]
- numpy [required: >=1.17, installed: 1.21.4]
- packaging [required: >=20.0, installed: 21.3]
- pyparsing [required: >=2.0.2,!=3.0.5, installed: 3.0.6]
- pillow [required: >=6.2.0, installed: 8.4.0]
- pyparsing [required: >=2.2.1, installed: 3.0.6]
- python-dateutil [required: >=2.7, installed: 2.8.2]
- six [required: >=1.5, installed: 1.16.0]
- setuptools-scm [required: >=4, installed: 6.3.2]
- packaging [required: >=20.0, installed: 21.3]
- pyparsing [required: >=2.0.2,!=3.0.5, installed: 3.0.6]
- setuptools [required: Any, installed: 59.5.0]
- tomli [required: >=1.0.0, installed: 1.2.2]
我尝试了不同版本的 matplotlib,但错误仍然存在。我也不知道我应该尝试哪个版本。导入 matplotlib 以前可以工作,但我不知道我当时使用的是什么 matplotlib 版本(或任何依赖项的版本)。 我在 Windows 上,使用虚拟环境并根据 https://pyinstaller.readthedocs.io/en/stable/bootloader-building.html 构建引导加载程序
【问题讨论】:
标签: python matplotlib pyinstaller