Atom、MacBook M1 中的 Xlwings 权限错误,“命令错误 -1743:用户已拒绝权限”
我最近从 Windows 转移到了新 MacBook Pro M1。
我的软件和操作系统的当前版本:
- macOS Monterey 12.2.1
- Anaconda 和 Jupiter Notebook(所有最新版本)
- Atom:1.59.0
- Python:3.9
- Xlwings 2.4
我的问题(参见附图),当为 xlwings 执行一个非常简单的测试代码时, xlwings包已成功导入,但是当我尝试创建excel App()实例时,MacOS或Atom(我不确定是哪一个)是抛出命令错误
import xlwings as xw
xw.App()
命令错误
---------------------------------------------------------------------------
EventError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/appscript/reference.py in __call__(self, *args, **kargs)
481 try:
--> 482 return self.AS_appdata.target().event(self._code, params, atts, codecs=self.AS_appdata).send(timeout, sendflags)
483 except aem.EventError as e:
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/aem/aemsend.py in send(self, timeout, flags)
91 errormsg = _defaultcodecs.unpack(errormsg)
---> 92 raise EventError(errornum, errormsg, eventresult)
93 if kae.keyAEResult in eventresult: # application has returned a value
EventError: Command failed: The user has declined permission. (-1743)
The above exception was the direct cause of the following exception:
CommandError Traceback (most recent call last)
/var/folders/wl/2tgm3h1j69l7w_63j50vg8_r0000gn/T/ipykernel_3668/1252992621.py in <module>
----> 1 xw.App()
~/opt/anaconda3/lib/python3.9/site-packages/xlwings/main.py in __init__(self, visible, spec, add_book, impl)
215 self.impl = xlplatform.App(spec=spec, add_book=add_book, visible=visible)
216 if visible or visible is None:
--> 217 self.visible = True
218 else:
219 self.impl = impl
~/opt/anaconda3/lib/python3.9/site-packages/xlwings/main.py in visible(self, value)
284 @visible.setter
285 def visible(self, value):
--> 286 self.impl.visible = value
287
288 def quit(self):
~/opt/anaconda3/lib/python3.9/site-packages/xlwings/_xlmac.py in visible(self, visible)
112 @visible.setter
113 def visible(self, visible):
--> 114 appscript.app('System Events').processes[its.unix_id == self.pid].visible.set(visible)
115
116 def quit(self):
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/appscript/reference.py in __call__(self, *args, **kargs)
516 return
517 raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
--> 518 raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
519
520 def AS_formatcommand(self, args):
CommandError: Command failed:
OSERROR: -1743
MESSAGE: The user has declined permission.
COMMAND: app('/System/Library/CoreServices/System Events.app').processes[its.unix_id == 3731].visible.set(True)
Press any key
我进行的测试:
- 使用终端(具有相同的anaconda env)成功执行了脚本,
- 使用Jupiter Notebook(具有相同的anaconda env)成功执行了代码
- 我尝试了在我的另一台带有 Atom 的 Windows 笔记本电脑上编写代码,它可以正常工作
- 我使用终端启动 Atom 并再次执行代码,它仍然显示相同的权限错误
有人可以帮忙解决这个问题吗?提前非常感谢。
I recently moved from Windows to the New MacBook Pro M1.
Current version of my software and OS:
- macOS Monterey 12.2.1
- Anaconda and Jupiter Notebook (all latest version)
- Atom:1.59.0
- Python: 3.9
- Xlwings 2.4
My issue (see attached pic), when execute a very simple test code for xlwings, the xlwings package is successfully imported, but when I am try to create excel App() instance, the MacOS or Atom (I am not sure which one) is throwing out Command Error
import xlwings as xw
xw.App()
Command Error
---------------------------------------------------------------------------
EventError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/appscript/reference.py in __call__(self, *args, **kargs)
481 try:
--> 482 return self.AS_appdata.target().event(self._code, params, atts, codecs=self.AS_appdata).send(timeout, sendflags)
483 except aem.EventError as e:
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/aem/aemsend.py in send(self, timeout, flags)
91 errormsg = _defaultcodecs.unpack(errormsg)
---> 92 raise EventError(errornum, errormsg, eventresult)
93 if kae.keyAEResult in eventresult: # application has returned a value
EventError: Command failed: The user has declined permission. (-1743)
The above exception was the direct cause of the following exception:
CommandError Traceback (most recent call last)
/var/folders/wl/2tgm3h1j69l7w_63j50vg8_r0000gn/T/ipykernel_3668/1252992621.py in <module>
----> 1 xw.App()
~/opt/anaconda3/lib/python3.9/site-packages/xlwings/main.py in __init__(self, visible, spec, add_book, impl)
215 self.impl = xlplatform.App(spec=spec, add_book=add_book, visible=visible)
216 if visible or visible is None:
--> 217 self.visible = True
218 else:
219 self.impl = impl
~/opt/anaconda3/lib/python3.9/site-packages/xlwings/main.py in visible(self, value)
284 @visible.setter
285 def visible(self, value):
--> 286 self.impl.visible = value
287
288 def quit(self):
~/opt/anaconda3/lib/python3.9/site-packages/xlwings/_xlmac.py in visible(self, visible)
112 @visible.setter
113 def visible(self, visible):
--> 114 appscript.app('System Events').processes[its.unix_id == self.pid].visible.set(visible)
115
116 def quit(self):
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/appscript/reference.py in __call__(self, *args, **kargs)
516 return
517 raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
--> 518 raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
519
520 def AS_formatcommand(self, args):
CommandError: Command failed:
OSERROR: -1743
MESSAGE: The user has declined permission.
COMMAND: app('/System/Library/CoreServices/System Events.app').processes[its.unix_id == 3731].visible.set(True)
Press any key
Test I carried out:
- the script was successfully executed with Terminal (with the same anaconda env)
- the code was successfully executed with Jupiter Notebook (with the same anaconda env)
- I tried the code on my other Windows laptop with atom, it works with no problem
- I launch Atom by using terminal and execute the code again, it still showing the same permission error
Could anyone help with the matter please? Much appreciate in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论