keyboard icon indicating copy to clipboard operation
keyboard copied to clipboard

Import Error on Replit (Chromebook - Linux)

Open ryantwt07 opened this issue 4 years ago • 2 comments

I'm creating a guessing game which requires the user to type "s" to start the game.

Operating System

Google Chromebook - ChromeOS 92.0.4515.162 (Official Build) (64-bit) Lenovo 500e Chromebook 2nd Gen Replit

Code

print("Welcome to the Colour Guessing Game!")
print("Press 'I' for instructions.")
print("Press 'S' to Start.")
started = False
while not started:
  from keyboard import is_pressed
  if is_pressed("s"):
     started = True
  elif is_pressed("i"):
     print("The system will generate a number from 1-1000. Try to guess the correct number generate d in 15 moves.")
  else:
    continue
else:
  print("Under Maintenance.")

Error

Traceback (most recent call last):
  File "main.py", line 7, in <module>
    if is_pressed("s"):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/keyboard/__init__.py", line 410, in is_pressed
    _listener.start_if_necessary()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/keyboard/_generic.py", line 35, in start_if_necessary
    self.init()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/keyboard/__init__.py", line 196, in init
    _os_keyboard.init()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/keyboard/_nixkeyboard.py", line 113, in init
    build_device()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/keyboard/_nixkeyboard.py", line 109, in build_device
    ensure_root()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/keyboard/_nixcommon.py", line 174, in ensure_root
    raise ImportError('You must be root to use this library on linux.')
ImportError: You must be root to use this library on linux.

ryantwt07 avatar Aug 30 '21 01:08 ryantwt07

I'm not very familiar with Replit, but does it run locally in your machine, or in a remote cloud server somewhere? If it's the first one, you need to invoke Replit as root. If it's the latter, there's not much you can do; you have to run keyboard on the machine that has the keyboard attached.

boppreh avatar Aug 30 '21 11:08 boppreh

This is expected behaviour, look in the Known limitations section: "To avoid depending on X, the Linux parts reads raw device files (/dev/input/input*) but this requires root."

Im not sure if you can run stuff as root on chromebooks. (And if replit runs in the cloud, this wont work anyways)

Secretowo avatar Oct 17 '21 15:10 Secretowo