使用pyinstaller时遇到AttributeError: Module ‘PyQt5‘ has no attribute ‘__version__‘的解决方法

使用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"

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
这个错误是由于`PyInstaller.compat`模块中没有`is_py312`属性导致的。 要解决这个问题,您可以尝试以下几个方法: 1. 确保您使用的是最新版本的PyInstaller。可以通过运行`pip install --upgrade pyinstaller`来更新PyInstaller。 2. 检查您的代码中是否有任何与`PyInstaller.compat`相关的导入语句。如果有,请尝试删除或更改这些导入语句,以避免与其他模块冲突。 3. 检查您的Python环境是否正确配置。特别是,确保您正在使用PyInstaller兼容的Python版本,并且所有依赖项都已正确安装。 如果以上方法都无法解决问题,您还可以尝试在PyInstaller的GitHub页面上搜索或报告此问题。其他用户可能已经遇到了类似的问题,并提供了解决方案。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Pyinstaller报错AttributeError: ‘module‘ object has no attribute ‘GetShortPathName](https://blog.csdn.net/lly1122334/article/details/120901499)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [AttributeError: module 'tensorflow.compat.v1' has no attribute '](https://download.csdn.net/download/qq_38766019/86272235)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值