python access /Library on macos


I am trying to write an install file to the /Library folder if the user doesn’t have it. I can run the code in "sudo python …" and it works.

However using pyinstaller and creating a packaged app gives me an Error 13 permission denied.

[Errno 13] Permission denied: ‘/Library/…’)

Is there a key value in Info.plist to grant full access to files? I have manually added full disk access to the app without luck. What are the necessary security measures needed to be able to get this to run?

Here is the Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
    <string>Access Camera</string>
    <string>Install Files For Driver</string>
Asked By: msj121



If you want to run a program with root privs without a terminal command line, you can do so via Applescript.

If the script doesn’t need a tty, this will work:

do shell script "python /path/to/your/python/script" with administrator privileges

If you Export that as an Application from Script Editor, you’ll get a double-clickable app that will pop up a dialog to get the user’s password/fingerprint and then run your Python code as root.

Answered By: Mark Reed