Home > Mobile >  How to run a Python file on Ubuntu that requires root privileges
How to run a Python file on Ubuntu that requires root privileges

Time:10-29

I just started experimenting with Python's keyboard module, and wanted to test out a few lines of code:

import keyboard
keyboard.write("Hello")

However, when I try to run the file from IDLE or from the terminal, there is an error message.

In IDLE: "You must be root to run this file from linux."

On root terminal: "Permission Denied."

Any suggestions on how to get this to run?

(Note: I have tried using other modules in various files and they worked fine, so I know my Python installation is fine). I am on Ubuntu 20.04.

Update: I tried running the file using sudo, but I got the same error message: Permission Denied

CodePudding user response:

You can try sudo command like sudo python3 script.py.

if it's don't work you can try these things;

  1. chmod x script.py
  2. python3 script.py
  • Related