无法在Pyinstaller中导入matplotlib



尝试导入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文件,就可以重现错误。

来自管道部门:

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以前也可以,但我不知道当时我使用的是哪个matplotllib版本(或任何依赖项的版本(。我在Windows上,使用虚拟环境,并根据https://pyinstaller.readthedocs.io/en/stable/bootloader-building.html

按照这里的建议,通过具体的matplotlib==3.2.2修复了如何使用带有matplotllib的pyinstaller来解决另一个问题

最新更新