python-3.x 为什么我不能在Ubuntu 20.04 LTS中使用Pyautogui?

l5tcr1uw  于 2022-11-26  发布在  Python
关注(0)|答案(2)|浏览(256)

我一直在Ubuntu上尝试使用Pyautogui,但我就是不能让它工作,而我在Windows上做起来却没有问题。不管我安装了什么依赖项,每次我尝试使用Pyautogui时,它都会返回:

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

如果我尝试: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.

如果我尝试: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(我试图用Pyautogui运行一个python文件的virtualenv的)

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

是否还有其他需要安装的依赖项?我不知道还能做什么。

njthzxwz

njthzxwz1#

该软件包有点奇怪。这可能会解决您的问题:

sudo apt-get install python-tk
cbeh67ev

cbeh67ev2#

注意:您必须在Linux上安装Tkinter才能使用MouseInfo。请执行下列程式:python3-tk python3-dev的安装程序
我也遇到过这个问题,即使使用sudo apt-get install python3-tk python3-dev也不起作用
首先尝试运行此命令,指定python版本,例如,在python 3.10中:

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

重新编译并重新安装python3.10,指定包含tcl、tk include和库的文件夹路径

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

重新安装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

编辑配置

cd Python-3.10.0
vim ./configure

搜索with-tcltk-includes/with-tcltk-libs并替换“..."中的部分,如下所示:

--with-tcltk-includes='-I/usr/include' 
--with-tcltk-libs='-L/usr/lib'
  • 提示:用于在vim \phrase中搜索 *

然后运行

./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

注意:将命令“make -j2”上的2替换为处理器内核数

相关问题