python3.10版本pyinstaller打包exe出现异常(ImportError: cannot import name ‘MutableSet‘ from ‘collections)解决方案

现在是凌晨12点41分,写完代码先把程序打包成exe文件,终端敲入打包命令

pyinstaller -F main.py

提示以下错误,这个错误是我头一次遇见,各种调试设置都是不行,无奈上网搜随还是找不到,貌似这个问题出现的并不多,我压根找不到靠谱的解决方案,去国外帖子搜随答案也是一筹莫展,唯一找到的一个出现一模一样问题的帖子,但是帖子也没有得到靠谱有利的回答。

(MyVenv) D:\PycharmProjects\love-with-python-master>pyinstaller -f sendlove.py
Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\PycharmProjects\MyVenv\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "d:\pycharmprojects\myvenv\lib\site-packages\PyInstaller\__main__.py", line 62, in run
    import PyInstaller.building.build_main
  File "d:\pycharmprojects\myvenv\lib\site-packages\PyInstaller\building\build_main.py", line 33, in <module>
    from ..depend.analysis import initialize_modgraph
  File "d:\pycharmprojects\myvenv\lib\site-packages\PyInstaller\depend\analysis.py", line 45, in <module>
    from ..building.datastruct import TOC
  File "d:\pycharmprojects\myvenv\lib\site-packages\PyInstaller\building\datastruct.py", line 18, in <module>
    from collections import MutableSet
ImportError: cannot import name 'MutableSet' from 'collections' (C:\Program Files\Python310\lib\collections\__init__.py)

接近放弃之时,突然想到了版本问题,我立马检查了库版本得到以下内容。

(MyVenv) D:\PycharmProjects\love-with-python-master>pip list
Package      Version
------------ --------
altgraph     0.16.1  
future       0.16.0  
macholib     1.10    
opencv-proto 0.3.0   
pefile       2018.8.8
Pillow       9.0.1   
pip          22.0.3  
pygame       2.1.2   
PyInstaller  3.3.1   
pypiwin32    223     
pywin32      303     
setuptools   57.0.0  
wheel        0.36.2  

看着pyinstaller 3.3.1版号恍然大悟,最新版本都有4.9了这个版本貌似太落后了,赶紧升级版本尝试能不能修复问题,功夫不负有心人,成功了。打包成功。
总结,解决方案:更新pyinstaller的版本即可

你可能感兴趣的:(笔记,python)