Mac 安装 xlwings

1、环境介绍

  • 我的环境介绍

    MacBook M1 + Python3 + PyCharm2021.1 + xlwings 0.23.1 + MicroSoft Excel 365

  • 一段代码

    执行这段代码

    if __name__ == '__main__':
        import xlwings as xw
    
        wb = xw.Book('Book1.xlsx')
        sheet = wb.sheets['template'].copy(name='report')
        sheet.render_template(title='A Demo!', table=[[1, 2], [3, 4]])
        wb.to_pdf()
    

2、PyCharm使用xlwings

  • PyCharm 使用 xlwings 的问题

    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/Users/kylewhite/dev/pythonProject/demo_project/file/test.py", line 4, in <module>
        wb = xw.Book('Book1.xlsx')
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/xlwings/main.py", line 539, in __init__
        for wb in app.books:
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/xlwings/main.py", line 64, in __iter__
        for impl in self.impl:
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/xlwings/_xlmac.py", line 235, in __iter__
        n = len(self)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/xlwings/_xlmac.py", line 200, in __len__
        return self.app.xl.count(each=kw.workbook)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aeosa/appscript/reference.py", line 518, in __call__
        raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
    appscript.reference.CommandError: Command failed:
    		OSERROR: -1743
    		MESSAGE: The user has declined permission.
    		COMMAND: app(pid=75376).count(each=k.workbook)
    

    在这里插入图片描述

  • 解决方案

    不用试了目前没有解决方案,解决方案的更新可以看这里,我已经提交了这个问题

    aem.aemsend.EventError: Command failed: The user has declined permission. (-1743) : PY-48616 (jetbrains.com)

    重点是:使用终端可以执行。当我第一次使用终端执行时,它向我要了权限,当我给了权限后,就可以执行了。所以我认为 Pycharm 没有权限导致的,Pycharm 甚至没有向我要权限

3、终端执行问题

  • xlwings的安装文档

    Confirmation (xlwings.org)

  • 第一个报错:raise ImportError(“Couldn’t find ‘cryptography’, a dependency of xlwings PRO.”) from None

    错误:
    在这里插入图片描述

    解决:

    pip3 install "xlwings[pro]"
    
  • 第二个报错:xlwings.LicenseError: Invalid license key.

    错误:
    在这里插入图片描述

    解决:

    去申请一个 xlwings 的 License,填写信息后你将获取收到一封邮件,然后直接将命令复制并运行
    在这里插入图片描述

    申请地址:https://www.xlwings.org/trial

    xlwings license update -k gAAAAABgnQwSIbTc_PuPNDDuPi0ehvxZsnSMe4tDA_9otuRQelH27J6gK6j5xhVrw5l3Ge5-unsT_-WC0YdMNEk3D
    
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值