Score:0

ImportError: You must be root to use this library on linux. Keyboard module doesn't work. Can you help?

ru flag

I have a code on pycharm, where it uses keyboard module to write 'Hello world!'. But when i run it, it says ImportError: You must be root to use this library on linux. I don't find answer to this question so i asked it from you. I use python 3.8 and i have done pip install, sudo install and even in the pycharm interpreter i have installed the package. Did anyone else see this problem? All help is good and i accept trying to help. And btw i am very noob on linux. I installed ubuntu yesterday.

EDITED: Here is the code:

import keyboard as kb
kb.write('Hello world!')

Its so simple so i didn't think i had to post it.

Nmath avatar
ng flag
If you need us to audit code, we need the code. Please edit your question and include details. As written, we don't know what you are trying to run, so we probably won't be able to answer.
ru flag
You should probably be executing this code inside of a `root` Python prompt instead of PyCharm. Running PyCharm as root can mess with permissions in a bad way for your home directory, whereas using PyCharm to edit the file and then have a separate terminal prompt open to execute your `.py` file with `sudo python3` might work for testing.
Score:1
us flag

You must use a root terminal (sudo -i or sudo su will change the user to root). Navigate to the directory which has the Python file you want to execute and run:

chmod +x yourfile.py

Where yourfule.py is the name of the file you want to execute.

Now, run yourfile.py as usual using python3.

python3 yourfile.py

Again, change yourfile.py with the name of the Python file you want to execute.

Someone avatar
my flag
There's no need to use a root terminal... Using a root terminal may break things. One can just use `sudo python3 file.py` to execute a file with root permissions.
Score:-3
pk flag

You need to run PyCharm as root. Using terminal, navigate to the folder where pycharm is located (for me it's here: '~/PyCharm/pycharm-community-2021.3.2/bin'), and type 'sudo bash pycharm.sh'

ru flag
This may break permissions in various locations, just an FYI.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.