Pycharm cannot get permission to control Excel(Mac)

Answered

Dear all

I want to use "xlwings" to control Excel, but I got error because I didn't get permission. However, pycharm didn't ask me the permission like other IDE used to.

For example, when I run the sample code below, MacOX will ask me "spyder want to contol..." I tried this in terminal as well, MacOX aksed me same thing. But pycharm didn't, just show error like below.

anyone has same problem?

(I have tried same things in Windows version pycharm , if successful)

 

 

0
9 comments

I believe this is the same issue: https://youtrack.jetbrains.com/issue/IDEA-219288 Unfortunately, there's no workaround an the moment.

0

yes...it is the same issue...

I thought it was a new bug. it surprise me the bug still not fixed...2 months..

0
Avatar
Permanently deleted user

2020.1 seems to have fixed this

0

Dear All,

I have just tried to use the same "xlwings" python lib, but still doesn't work. I was googling a debugging for a day (looked for Issue 1146, Issue 1262, Issue 1266)  it works (and asks for the correct permission) in iTerm2, Terminal, but does not work from PyCharm Console. I tried also the following command in Terminal:

tccutil reset AppleEvents

as well as I reinstalled PyCharm but nothing has changed.

 

Basic run code:

import xlwings as xw

app = xw.Book()

 

The error message is the following:

Traceback (most recent call last):
File "/usr/local/anaconda3/lib/python3.8/site-packages/aeosa/appscript/reference.py", line 482, in __call__
return self.AS_appdata.target().event(self._code, params, atts, codecs=self.AS_appdata).send(timeout, sendflags)
File "/usr/local/anaconda3/lib/python3.8/site-packages/aeosa/aem/aemsend.py", line 92, in send
raise EventError(errornum, errormsg, eventresult)
aem.aemsend.EventError: Command failed: The user has declined permission. (-1743)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-4bab09758204>", line 1, in <module>
runfile('/Volumes/GoogleDrive/My Drive/Code/Python/python-home-kezdo/test-excel-python-02-xlwings.py', wdir='/Volumes/GoogleDrive/My Drive/Code/Python/python-home-kezdo')
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Volumes/GoogleDrive/My Drive/Code/Python/python-home-kezdo/test-excel-python-02-xlwings.py", line 6, in <module>
app = xw.Book()
File "/usr/local/anaconda3/lib/python3.8/site-packages/xlwings/main.py", line 557, in __init__
impl = apps.active.books.add().impl
File "/usr/local/anaconda3/lib/python3.8/site-packages/xlwings/main.py", line 3812, in add
return Book(impl=self.impl.add())
File "/usr/local/anaconda3/lib/python3.8/site-packages/xlwings/_xlmac.py", line 203, in add
if self.app.visible:
File "/usr/local/anaconda3/lib/python3.8/site-packages/xlwings/_xlmac.py", line 110, in visible
return appscript.app('System Events').processes[its.unix_id == self.pid].visible.get()[0]
File "/usr/local/anaconda3/lib/python3.8/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('/System/Library/CoreServices/System Events.app').processes[its.unix_id == 80947].visible.get()


I'm using the following configuration:

PyCharm 2021.1.1
Python 3.8.5 (with Anaconda)
xlwings 0.23.0
MacOS 10.15.7 (Catalina)
0
Avatar
Permanently deleted user

I've seen both PyCharm and VS Code fix this and break this again depending on the release. A workaround is always to start PyCharm from the Terminal. It's easiest to set an alias like this in your ~/.zshrc (or ~/.bash_profile on older macOS):

alias pycharm=/Applications/PyCharm.app/Contents/MacOS/pycharm

This allows you to start PyCharm from the Terminal by typing:

pycharm
1

Thank you Felix, it works in this way.

0

Yes, it works. Thanks!!

0

I'm having a permission issue with the workaround. Any suggestions?

Error:

zsh: permission denied: /Users/cotani/Applications/JetBrains Toolbox/PyCharm Professional Edition for Apple Silicon.app

 

0

Hello @C Otani, 

 

Could you please submit an issue on https://youtrack.jetbrains.com/issues/PY  with attached:

1. code example

2. steps to reproduce

3. logs folder zipped from ***Help | Collect logs and Diagnostic Data*** 

 

 

 

0

Please sign in to leave a comment.