使用pyinstaller时遇到AttributeError: Module ‘PyQt5’ has no attribute 'version’的解决方法
如题,在使用python打包exe可执行文件时,遇到了这种异常,分享一下我的解决方法:
首先,我并没有直接使用PyQt5,但是在打包过程中出现了该异常,在网上查询后,大多数的解决方法是在项目环境下安装PyQt5
pip install PyQt5
但是我在安装后依然产生该异常。
我的解决的办法是:通过手动添加__version__ = "5.15.4"到flow_cell/Lib/site-packages/PyQt5/init.py。其中,flow_cell是一个安装了PyQt5的虚拟环境。
Before:
# Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
#
# This file is part of PyQt5.
#
# This file may be used under the terms of the GNU General Public License
# version 3.0 as published by the Free Software Foundation and appearing in
# the file LICENSE included in the packaging of this file. Please review the
# following information to ensure the GNU General Public License version 3.0
# requirements will be met: http://www.gnu.org/copyleft/gpl.html.
#
# If you do not wish to use this file under the terms of the GPL version 3.0
# then you may purchase a commercial license. For more information contact
# info@riverbankcomputing.com.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
After:
# Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
#
# This file is part of PyQt5.
#
# This file may be used under the terms of the GNU General Public License
# version 3.0 as published by the Free Software Foundation and appearing in
# the file LICENSE included in the packaging of this file. Please review the
# following information to ensure the GNU General Public License version 3.0
# requirements will be met: http://www.gnu.org/copyleft/gpl.html.
#
# If you do not wish to use this file under the terms of the GPL version 3.0
# then you may purchase a commercial license. For more information contact
# info@riverbankcomputing.com.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
__version__ = "5.15.4"