pythonuser-interfaceimportpyautoguichromebook

Can't we import 'pyautogui' into google colaboratory?


I'm new to python and I have some issues importing a few modules on google colaboratory which include gui.

After giving the command : !pip install pyautogui, colab installs it without any error but when I ask it to import that module,it gives the error:

KeyError                                  Traceback (most recent call last)
<ipython-input-3-89465ec01d66> in <cell line: 3>()
      1 # Screen Shot Taker
      2 get_ipython().system('pip install pyautogui')
----> 3 import pyautogui

2 frames
/usr/lib/python3.10/os.py in __getitem__(self, key)
    678         except KeyError:
    679             # raise KeyError with the original key value
--> 680             raise KeyError(key) from None
    681         return self.decodevalue(value)
    682 

KeyError: 'DISPLAY'

After going through some websites, I figured out that colab can't import modules having gui but I'm not sure if this is correct.

So, is there any other way to import pyautogui into colab, or we can't import it due to some reason?

If we can't import it, are there any other online ides that can ? A really important thing that I'm working on a chromebook, not on a laptop or PC.


Solution

  • According to korakot's answer to How to simulate python key presses in Google Collab notebook?:

    ...Google Colab is run on a machine instance in Google Cloud. Python there cannot gain access to your keyboard/monitor. You interact with Colab through the browser only.