asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.24k forks source link

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

Open adriangabura opened 2 years ago

adriangabura commented 2 years ago

Hi, I run Fedora 35 Workstation, what apt is this talking about even?

I installed all dependencies from Fedora repositories python3-tkinter, python3-devel and python3-xlib. I still get this.

MaximumMaxxx commented 2 years ago

Also happening on Fedora 36

adriangabura commented 2 years ago

Also happening on Fedora 36

Yeah clearly. This package does not check for the kind of distro. Will all due respect to Debian, that's not the only distro by far.

MaximumMaxxx commented 2 years ago

So after a bit of digging it seems like the error actually originated from the Mouseinfo package which seems to have some issue with import tkinter in fedora. I’ll do a bit more testing but it might be a good idea to make an issue on the that library.

MaximumMaxxx commented 2 years ago

I believe it’s this repo https://github.com/asweigart/mouseinfo

adriangabura commented 2 years ago

So after a bit of digging it seems like the error actually originated from the Mouseinfo package which seems to have some issue with import tkinter in fedora. I’ll do a bit more testing but it might be a good idea to make an issue on the that library.

@MaximumMaxxx Do you incidentally use pyenv?

I use pyenv and when I had pyenv global set not to system but to another version it had problems importing tkinter.

Besides tkinter is in the standard library so it should be compiled in the build as far as I can say...

This code gave a ModuleNotFoundError: python -c "import tkinter"

MaximumMaxxx commented 2 years ago

That makes sense, I was using the builtin venv but seems like that’s what the issue is. I’ll mess with my venv config to see if that solves it.

AaronLaw commented 2 years ago

On Arch Linux, sudo pacman -S tk works for installing pyautogui

zakariamanssouri commented 2 years ago

sudo pacman -S tk thanks it's working

mitaharumi commented 2 years ago

if anyone is having this problem on ubuntu, this may help


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 

if the above command doesn't solve, after hours of despair i found this topic how to install tkinter for python 3.8, there is this tutorial


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

covalspace commented 1 year ago

Any solution? Daniela's method did not work for me on Ubuntu. I'm just trying to use pyautogui on ubuntu so I can free up my mac for other things.

Took me less than a minute to run my script on Mac and I've spent 4 hours troubleshooting just to get it running on linux with absolutely no solutions.

gekitsuu commented 1 year ago

TL;DR @covalspace for me, it was a matter of switching pyenv back to the system installed python with pyenv global system.

The instructions that tell you to sudo apt-get install are installing tk to the system version of python. Since I was using pyenv to use a newer version of python my python move_mouse.py script wasn't using the same version that had the tk libs available. Once I changed back to the system python I did another pip install pyautogui and everything worked as expected.

covalspace commented 1 year ago

Ok so basically you're saying I am forced to use an out of date version of python because Linux requires "tkinter" to install pyautogui?

That is unacceptable by my standards.

I just ran my script on a mac VM in my Mac and am a happy boy.

I am beginning to believe that Linux is the absolute worst option available for anything that isn't ultra privacy related.

iamtalhaasghar commented 1 year ago

I am using fedora 38. Upon installing the python3-tkinter package the problem was fixed.

sudo dnf install python3-tkinter

xloc commented 10 months ago

Just in case anyone else using the same setting: I use homebrew-linux on ubuntu to install my python environment

To get tk working, you need to brew install python-tk@3.? where 3.? is the version of interpreter you are using.

wifitecture commented 9 months ago

Using fedora 39 here and running Python 3.11 in my venv with the dependencies installed using sudo dnf install python3-tkinter python3-devel did not solve the issue.

The only solution that worked for me was to use Python 3.10 instead and install the dependencies on it.

adriangabura commented 9 months ago

Using fedora 39 here and running Python 3.11 in my venv with the dependencies installed using sudo dnf install python3-tkinter python3-devel did not solve the issue.

The only solution that worked for me was to use Python 3.10 instead and install the dependencies on it.

You run it on venv? That could be the issue. Check for yourself if tkinter is even imported. And make sure that you check on the system python for which you installed the packages. Use which to check what python path you're executing. If there is something related to tkinter, the issue has nothing to do with pyautogui. So check that first.

josephosan commented 6 months ago

On Arch Linux, sudo pacman -S tk works for installing pyautogui

worked for me, thanks.

RedHeadphone commented 5 months ago

I am using fedora 38. Upon installing the python3-tkinter package the problem was fixed.

sudo dnf install python3-tkinter

If anyone stumbles on this issue, for Fedora run the below 2 commands, and the issue will be fixed.

  1. sudo dnf install python3-tkinter
  2. yum install python-devel