Whenever I run any .py script with sudo, even simple ones, I get the error "[Errno 13] Permission denied" on Linux. The reason I want to run a Python script with sudo in the first place is because the "keyboard" module in one of my files needs root permissions to function properly.
import keyboard
def record():
events = keyboard.record(until='esc')
return events
def process_recorded_letters(events):
letter_events = ""
for key in events:
if key.event_type == 'down' and key.name != 'shift' and key.name != 'space':
letter_events += key.name
return letter_events
events = record()
print(process_recorded_letters(events))
I did the simple things like checking that I was actually the root user, checking if the files actually existed, and changing the file permissions with chown and chmod, but nothing worked, I kept on getting the Errno 13 error. I also tested running the script on a different Linux distro and I still got Errno 13, so it's definitely some problem on my end.