I am not sure why PyCharm isn't working correctly. I am using Visual Studio Code and I had the same problem as you.
A. Terminal.app (temporary solution)
If we run it in the Terminal.app and give that permissions, then it should work for you like it did for me.
- Settings ->
Security & Privacy
- Click on the
Privacy tab
- Scroll and click on the
Accessibility Row
- Click the
+
- Navigate to
/System/Applications/Utilities/ or wherever the Terminal.app is installed
- Click okay.
Alternate solution here
B. py2app (distributable app)
Another approach is to use py2app to make a *.app and give that permissions.
- Make a setup.py
from setuptools import setup
APP = ['main.py'] # points to your main python file
DATA_FILES = []
OPTIONS = {
'packages': ['pynput'] # include your other dependencies here
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
- In the terminal, run
pip install py2app
- And then,
python setup.py py2app
- This will make a folder named
dist.
- Add
./dist/main.app to the Accessibility tab using the same steps as the first solution.
- Just to be sure, add
main (in the folder ./dist/main.app/Contents/MacOS/) to the Accessibility tab. You can type the directory in the window by pressing ⌘⇧G
- Either open the app in Finder or run it in the console.