MacOS – Access denied when creating a Python file

macospythonSecurity

I'm trying to compile a file using Python and I receive this message:

error: could not create '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/tulip': Permission denied

Why is the permission denied? How can I fix this?

Best Answer

It's trying to create a file in the system installation of Python (i.e. it's going in the root Library folder). That folder is only writeable by root (to prevent damaging important system files), hence why you're getting a permission error.

Running the command with sudo preceding it, i.e. sudo foo bar will give you the proper permissions, after asking for your password. Alternatively, you can use virtualenv to set up your own Python environment that will allow you to mess around without worrying about changing the system default install.