ModuleNotFoundError: No module named ‘openpyxl‘

ModuleNotFoundError: No module named 'openpyxl'

一、问题现象

执行python脚本的时候报错:

ModuleNotFoundError: No module named 'openpyxl'

其实我已经安装过openpyxl了;

# 安装命令
pip install openpyxl
# 查找已安装的模块
pip list |grep openpyxl
DEPRECATION: The default format will switch to columns in the future. 
You can use --format=(legacy|columns) (or define a format=(legacy|columns) 
in your pip.conf under the [list] section) to disable this warning.
openpyxl (2.6.4)

但是为什么还是会报错呢?

二、问题原因

  由于python有多个版本:python2和python3,并且两个版本的模块还不能共用,因此有不同的pip版本:pip和pip3,分别用于安装python2和python3的模块;因此需要使用不同的pip版本安装python需要的模块;
python2的模块安装命令:

pip install openpyxl

python3的模块安装命令:

pip3 install openpyxl

如果pip3没有安装,则需要安装pip3:

sudo apt install python3-pip

最终问题就解决了:

pip list |grep openpyxl
DEPRECATION: The default format will switch to columns in the future. 
You can use --format=(legacy|columns) (or define a format=(legacy|columns) 
in your pip.conf under the [list] section) to disable this warning.
openpyxl (2.6.4)

pip3 list |grep openpyxl
DEPRECATION: The default format will switch to columns in the future. 
You can use --format=(legacy|columns) (or define a format=(legacy|columns) 
in your pip.conf under the [list] section) to disable this warning.
openpyxl (3.1.2)
  • 13
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用和中显示,出现了"ModuleNotFoundError: No module named 'openpyxl'"的错误。这个错误表示在运行程序时找不到openpyxl模块。这可能是由于打包过程中没有正确包含openpyxl模块导致的。为了解决这个问题,您可以尝试以下几个步骤: 1. 确保您已经正确安装了openpyxl模块。您可以使用命令`pip install openpyxl`来安装该模块。 2. 确保您在打包项目时已经将openpyxl模块包含在内。您可以使用pyinstaller的`--hidden-import`选项来明确指定需要包含的模块。例如,使用命令`pyinstaller --hidden-import=openpyxl your_script.py`来打包项目。 3. 如果您已经尝试了上述步骤但问题仍然存在,那可能是因为pyinstaller与openpyxl的版本不兼容。您可以尝试降低openpyxl的版本或升级pyinstaller的版本来解决兼容性问题。 综上所述,您可以通过确保正确安装openpyxl模块并正确打包项目来解决"ModuleNotFoundError: No module named 'openpyxl'"的错误。希望这对您有所帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [pyinstaller打包openpyxl和pandas包,报错ModuleNotFoundError openpyxl](https://blog.csdn.net/weixin_44475303/article/details/130587920)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [python 报错:ModuleNotFoundError: No module namedopenpyxl‘,安装openpyxl后还是报错解决方法。](https://blog.csdn.net/hajiaojh/article/details/119579795)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值