I have tried to use pyautogui and keyboard library in python but it shows error
You should use sudo python3 spam.py instead of python3 spam.py.
sudo python3 spam.py
python3 spam.py
You can directly install the library using pip3 install PyAutoGUI and pip3 install keyboard.
pip3 install PyAutoGUI
pip3 install keyboard