Mac/Ventura permissions error with os module (SOLVED)

Hi - brand new here, and very much python beginner. Just installed python 3 on M2 Mac running venture. Failed on my first attempt with permissions error (see below)

So far I’ve given full disk access to terminal, idle, and python launcher (will be removed once I’ve fixed this issue)

Thanks for any help.

Blockquote
import os
directory = os.getcwd()
print(directory)

Gives

Blockquote
Traceback (most recent call last):
File “/Users/anthonycollins/Documents/Python/helloworld.py”, line 3, in
directory = os.getcwd()
PermissionError: [Errno 1] Operation not permitted

I think you need to give your terminal program access to the documents folder.
You can do this in System Setting/Privacy & Security/Files and Folders.

You should have seen a popup asking if your want an app to access your documents and you likely said no.

I recommend iterm2 in place of the apple terminal program, from iterm2.com, as its much nicer to work with.

1 Like

Terminal already has full disk access - doesn’t that cover documents?

Suggest you also allow access to documents as well.
Not sure that full access mean all the folders.

OK, so to add documents I had to remove full disc access.

I then tried to access the documents folder from the terminal and was prompted to give permission. I selected to give access, then confirmed it was there in settings/privacy.

Still got the same error.

I then re-applied full disk access - which then take priority over the documents permission (the documents radio button is replaced with a non selectable “full disk access”. So I think is is safe to assume that full disk access grants permissions everywhere - verified by creating a text file in documents using nano.

I am also able to create files in other locations (eg downloads) without issue.

Thanks for taking the time so far - but I don’t think the problem here is with terminal file access permissions.

Copy the .py file out of documents into your home directory.
Can you now run the program?
I am reasonable sure it is macos security that you is stopping this from work.

Thanks for getting back - I’ve fixed it. For the benefit of anyone with similar problems:

I found this thread:

The user there solved the problem by logging out of apple ID and logging back in. I tried that and it didn’t help (wish I hadn’t - now resyncing all my photos :roll_eyes:)

However, he also diagnosed that solution by creating a new user account and trying there. This I did, and the operation worked in the new user account. I checked permissions there, and found that the app “python” was granted access to documents.

Logged back into my normal account, gave python access to documents, and it now works.

Thanks Barry for your time spent helping me.

(Can I set this to solved other than by adding the word to the title?)

1 Like

been trying to get PyPDF2 to work for 30 minutes and your comment was exactly what i needed!

1 Like