This question already has an answer here:

I'm try running a Python script that uses the GPIO pins but I get an error telling me that it doesn't have access to dev/mem and I should try running as root.

I don't know how to run a Python script as root, how do I do this?

marked as duplicate by Aurora0001, Ghanima Jan 1 at 22:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


From the terminal instead of doing python yourProgram.py, do sudo python yourProgram.py. It will ask for your password so type it and it should run.

Of course if it is python3 do sudo python3 yourProgram.py

Not the answer you're looking for? Browse other questions tagged or ask your own question.