问题描述
pyinstaller生成包含pyqt5的exe文件的时候,对话框报错“qt.qpa.plugin: Could not load the Qt platform plugin “windows” in “” even though it was found”。
本人部分库版本:
anaconda 2020.02
由于项目需要,通过降级(方法见:https://zhuanlan.zhihu.com/p/97790723)把默认的python3.7降级到python3.6
更新特定版本的库用:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller==4.0
在尝试了以下方法后均无效
- https://www.likecs.com/show-266823.html
这个极其不推荐哦,建议尝试的时候做好备份,覆盖掉的文件是Qt-designer的必要组件,会导致designer打不开。 - https://blog.csdn.net/nima1994/article/details/81106902
- https://blog.csdn.net/sgcc_zhs/article/details/18237957
方法
创建新的虚拟环境,然后在新的环境下安装pyinstaller,然后生成exe文件,就可以了(可能是anaconda部分包不兼容的问题,新的虚拟环境下包少,所以出错的概率就小,总之就是莫名其妙)
- 创建一个名为“xuni1”新的虚拟环境
打开新的cmd窗口,输入
conda create -n xuni1 python=3.6
一路“Yes”
2. 在虚拟环境中安装必要的库(其实只有pyinstaller一个)
本人用vscode,打开后在左下角选择解释器Interpreter
选择解释器路径
解释器的路径应该是新建的虚拟环境下的
查看虚拟环境的位置,用:
conda env list
去“xuni1”的目录下选择python.exe
- pyinstaller生成exe文件
pyinstaller -F Your_Python_File_Name.py
大功告成