1

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

2
  • 1
    Are you aware of sudo? sudo script.py? If this is foreign to you, I would recommend you brush up on your Linux/Unix basics before continuing. Commented Oct 28, 2021 at 18:04
  • What do you mean by "root terminal"? And are you sure that's the full error message? Normally you should get the name of the file too, like test.py: Permission denied Commented Oct 28, 2021 at 18:08

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

4 Comments

Why python3 script.py? You need to be root to use the keyboard module.
I am the root user, but it still won't run. Error message: Permission Denied
python3 or python command allows you to run your python file. If you use python2.x.x you can use python but if you use python3.x.x you can use python3 command
did you try chmod +x command? beacuse this problem seems like for your python file haven't enough permission
0

You can go to the directory where the file saved. Run following command by opening the terminal in that directory.

python3 file_name.py

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.