Does anyone tried to control mouse cursor position and click in Python application for Raspbian before?

I am refering to this website: https://pyautogui.readthedocs.io/en/latest/mouse.html#mouse-movement

I tried to run the sampel code given in this page as below:

#! python3
import pyautogui, sys
print('Press Ctrl-C to quit.')
    while True:
        x, y = pyautogui.position()
        positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
        print(positionStr, end='')
        print('\b' * len(positionStr), end='', flush=True)
except KeyboardInterrupt:

I got the import error which say no module named pyautogui, even I had installed the pyautogui with the following command:

sudo pip

Can anyone advice me on this? Also if there is other way to control mouse position and click can suggest me as well.

  • If you are using Python3 don't use pip - try pip3 – Milliways May 8 '19 at 6:34
  • @alpha91 I googled forum discussions on installing pyautogui and followed their suggestions to install first other related packaged such as pip3.2, pip3, pyton-xlib, python-tk, python-dev etc. All went well, except the last step "pip3 install pyautogui", with error message on Pillow. I guess my stretch 2019apr does not like the Pillow thing. So I gave up. – tlfong01 May 8 '19 at 7:24
  • Hi Milliways, had tried it but still the same. – alpha91 May 8 '19 at 8:02
  • Hi tlfong01, I successfully installed all the pyautogui, just that now when i run the sample code from the website i mentioned, it still having error with no module named pyautogui. Even after i reboot the Pi it still same. – alpha91 May 8 '19 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.