After installing macOS 10.15 Catalina I am getting the following error for simple file and directory operations in Python 3.x: "PermissionError: [Errno 1] Operation not permitted"
Several operations trigger this error including opening an existing file from the cwd using open(...,'rb'), listdir() and getcwd().
After updating to Catalina and finding that Anaconda and Spyder wouldn't open I read about some of the problems. I removed Anaconda and re-installed it in /Users/myname/ using the .sh terminal installer. Conda and Spyder now open but I still can't perform the operations above.
This works:
os.chdir(basedir)These do not work and throw the error above:
os.getcwd()
Traceback (most recent call last): File "<ipython-input-3-a78b1fb2bab9>", line 1, in <module> os.getcwd()
PermissionError: [Errno 1] Operation not permittedos.listdir()
Traceback (most recent call last): File "<ipython-input-2-67fdccf289bf>", line 1, in <module> os.listdir()
PermissionError: [Errno 1] Operation not permittedf=open([pre-existing file],'rb')However, this does NOT throw the error:
f=open('f1.txt','wb')
f.close()
f=open('f1.txt','rb')I've already tried setting Full Disk Access permissions for Anaconda and Spyder.
79 Answers
Go to System Preference->Security and Privacy.
Now look at the following image, see Label 1
On the left side click on Full Disk Access see Label 2
Now click on bottom left lock icon and enter password to make changes, see Label 3
Now click on + sign button, see Label 4
Browse the terminal app from Application -> Utilities
Now Terminal added with permission.
Done.
1If you encounter this issue with Workflows / Automator scripts like I did, the following might help:
- Open
System Preferences->Security & Privacy->Privacy - Click the lock in the bottom left and enter your password to allow changes
- Under 'Full Disk Access' click the '+' sign
- Add
Finder(to quickly find it, pressCMD+Shift+Gand enter/System/Library/CoreServices/Finder.app)
This should make all workflows work (again)!
Solved:
What I did I create a new folder I call it 'dev' in my user folder and moved all my files & folders in there, then the permission error disappeared.
Hope this will help you as well.
1I had the same problem and went to the System Preferences and under Security and Privacy > Developer Tools tab, added the Anaconda program under "Allow Apps below to run software locally...." and restarted the anaconda program and it worked.
EDIT: Something else i observed since i tried out this solution was that it only works when i run spyder from the terminal as a bash command.
To access folder and files.
- Go to system preferences
- go to security and privacy.
- In the privacy tab, select the files and folders in the left dialog. Unlock the make changes and select the terminal.
I had similar problem with PyCharm which was unable to install any packages. Running chown on the file pyvenv.cfg and setting the same user as it was set for that file before solved the problem.
In Full Disk Access section add Intellij or some IDE else would do the trick. For more:
I encountered this error because I attempted to start the http server in a directory I had deleted.
I was getting this error when using Pathlib.Path.rmdir(). The issue was not permission, even though that was the error I was getting and lead me here, the documentation says the directory should be empty and mine wasn't. I used shutil.rmtree instead and it worked without granting any of the permissions mentioned here.