Why can't I use Pyautogui in Ubuntu 20.04 LTS?

Viewed 1390

I've been trying to use Pyautogui at Ubuntu, but I simply can't make it work, while I have no trouble doing it at Windows. It doesn't matter what dependency I install, everytime I try to use Pyautogui, it returns:

NOTE: You must install Tkinter on Linux to use MouseInfo. Run the following: sudo apt-get install python3-tk python3-dev

And if I try: sudo apt-get install python3-tk python3-dev

python3-dev is already the newest version (3.8.2-0ubuntu2).
python3-tk is already the newest version (3.8.5-1~20.04.1).
0 upgraded, 0 newly installed, 0 to remove, and 0 not upgraded.

And if I try: pip3 install pyautogui

Requirement already satisfied: pyautogui in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (0.9.52)
Requirement already satisfied: pymsgbox in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (from pyautogui) (1.0.9)
Requirement already satisfied: PyTweening>=1.0.1 in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (from pyautogui) (1.0.3)
Requirement already satisfied: pyscreeze>=0.1.21 in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (from pyautogui) (0.1.26)
Requirement already satisfied: pygetwindow>=0.0.5 in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (from pyautogui) (0.0.9)
Requirement already satisfied: mouseinfo in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (from pyautogui) (0.1.3)
Requirement already satisfied: python3-Xlib in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (from pyautogui) (0.15)
Requirement already satisfied: pyrect in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (from pygetwindow>=0.0.5->pyautogui) (0.1.4)
Requirement already satisfied: Pillow>=6.2.1 in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (from pyscreeze>=0.1.21->pyautogui) (8.0.1)
Requirement already satisfied: pyperclip in /home/lucas/.virtualenvs/recursos/lib/python3.8/site-packages (from mouseinfo->pyautogui) (1.8.1)

pip freeze > requirements.txt (of the virtualenv that I tried to run a python file with Pyautogui)

altgraph==0.17
asgiref==3.3.1
beautifulsoup4==4.9.3
Django==3.1.3
django-bootstrap4==2.3.1
evdev==1.3.0
MouseInfo==0.1.3
mypy==0.790
mypy-extensions==0.4.3
passlib==1.7.4
Pillow==8.0.1
playsound==1.2.2
PyAutoGUI==0.9.52
PyGetWindow==0.0.9
pyinstaller==4.1
pyinstaller-hooks-contrib==2020.10
PyMsgBox==1.0.9
pynput==1.7.1
pyperclip==1.8.1
PyRect==0.1.4
PyScreeze==0.1.26
python-xlib==0.29
python3-xlib==0.15
pytube==10.0.0
PyTweening==1.0.3
pytz==2020.4
six==1.15.0
soupsieve==2.0.1
sqlparse==0.4.1
typed-ast==1.4.1
typing-extensions==3.7.4.3

Are there other dependencies that I need to install? I don't know what else to do.

2 Answers

That package is a bit weird. This might fix your issue:

sudo apt-get install python-tk

NOTE: You must install Tkinter on Linux to use MouseInfo. Run the following: sudo apt-get install python3-tk python3-dev

i had this problem too, even with sudo apt-get install python3-tk python3-dev it ditn't work.

firstly try to run this command specifying python version, for example, in python 3.10:

sudo apt-get install python3.10-tk python3-dev 

so after hours of despair i found this link topic how to install tkinter for python 3.8


basically i solved my problem by doing this:

recompile and reinstall python3.10 specifying path to folders with tcl, tk includes and libraries

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev python-tk python3-tk tk-dev

reinstall python 3.10

wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz
tar -xvf Python-3.10.0.tgz

edit configure

cd Python-3.10.0
vim ./configure 

search for with-tcltk-includes/with-tcltk-libs and replace part in "...", looking like this:

--with-tcltk-includes='-I/usr/include' 
--with-tcltk-libs='-L/usr/lib'

hint: for search in vim \phrase to search

then run

./configure
make -j2    
sudo make install
sudo ./configure --with-tcltk-includes='-I/usr/include -I/usr/include/tcl' --with-tcltk-libs='-L/usr/lib -ltcl -ltk' --enable-optimizations

note: replace 2 on command "make -j2" by number of processor cores

Related