How do I get rid of 'IOError: 13, 'Permission denied'' on Mac OS X

28,031

The permissions for the folder you are trying to copy the file to are not open enough for you to perform this operation as the user you are are running the script with. This is not really a Python issue. You need to either give the user write permissions to that folder or you need to run the script as root.

To run the script as root:

sudo python your_python_script.py

I believe you'll need to be the Admin user for that to work. 'sudo' is a command that means 'do this as the super user'.

To change the permissions of your folder you could try

sudo chmod a+rw /path/to/folder/that/you/want/to/write/to

Again, you would be doing this as the superuser, chmod is a command to change the permissions of a file or directory. 'a+rw' translates as 'give all users read/write permission. This might be a bad idea... but it sounds like you are just running this locally on your machine.

Share:
28,031
Admin
Author by

Admin

Updated on August 01, 2020

Comments

  • Admin
    Admin almost 4 years

    Here is my Code that I'm trying to run on Mac OS X:

    import getpass #Needed for fetching username
    import shutil #Needed for moving Files
    import os
    var_username = getpass.getuser() #gets username and returns as variable
    source_file = r"/Users/%s//Downloads/LogNLock/com.lognlock.loginhook.plist" %(var_username) #the destination of the source file
    destination = r"/Library/LaunchAgents" #the target destination for the file to go
    shutil.copy(source_file, destination) #moves the source file to the destination folder
    

    And I've googled around and can't figure out why it won't work. Background info: it works when moving files from the desktop to documents for example but I think i need to somehow how root user privileges. im on the administrator account right now.

  • Admin
    Admin almost 12 years
    How would I do either of those things? I'm very new.