pyautogui问题解决方案记录(因为使用了:pyautogui.locateCenterOnScreen(img, confidence=0.9))

本人环境:win10 1909. Python 3.9.13

不想多余看,只想直接解决,直接安装下面的库

pip install pyautogui
pip install pillow
pip install opencv-python

# 我安装的版本信息
C:\Users\gsp>pip list
Package       Version
------------- --------
MouseInfo     0.1.3
numpy         1.23.5
opencv-python 4.6.0.66
Pillow        9.3.0
pip           22.3.1
PyAutoGUI     0.9.53

pip永久设置成国内源

其实就是写了个配置文件。我的是:C:\Users\gsp\AppData\Roaming\pip\pip.ini

# 清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
# 豆瓣源
pip config set global.index-url http://pypi.douban.com/simple/

安装pyautogui没什么难度,直接pip

pip install pyautogui

# 如果临时从国内源安装
pip install pyautogui -i https://pypi.tuna.tsinghua.edu.cn/simple

由于使用pyautogui.locateCenterOnScreen,需要Pillow

没装Pillow前的报错信息

  File "C:\Users\gsp\Desktop\XXX.py", line 34, in getlocation
    location = pyautogui.locateCenterOnScreen(img, confidence=0.9)
  File "C:\all_software\Python\Python39\lib\site-packages\pyautogui\__init__.py", line 175, in wrapper
    return wrappedFunction(*args, **kwargs)
  File "C:\all_software\Python\Python39\lib\site-packages\pyautogui\__init__.py", line 207, in locateCenterOnScreen
    return pyscreeze.locateCenterOnScreen(*args, **kwargs)
  File "C:\all_software\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 413, in locateCenterOnScreen
    coords = locateOnScreen(image, **kwargs)
  File "C:\all_software\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 372, in locateOnScreen
    screenshotIm = screenshot(region=None) # the locateAll() function must handle cropping to return accurate coordinates, so don't pass a region here.
  File "C:\all_software\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 144, in wrapper
    raise PyScreezeException('The Pillow package is required to use this function.')
pyscreeze.PyScreezeException: The Pillow package is required to use this function.

安装命令

pip install pillow

由于使用confidence参数,需要OpenCV

没装OpenCV 前的报错信息

  File "C:\Users\gsp\Desktop\XXX.py", line 34, in getlocation
    location = pyautogui.locateCenterOnScreen(img, confidence=0.9)
  File "C:\all_software\Python\Python39\lib\site-packages\pyautogui\__init__.py", line 175, in wrapper
    return wrappedFunction(*args, **kwargs)
  File "C:\all_software\Python\Python39\lib\site-packages\pyautogui\__init__.py", line 207, in locateCenterOnScreen
    return pyscreeze.locateCenterOnScreen(*args, **kwargs)
  File "C:\all_software\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 413, in locateCenterOnScreen
    coords = locateOnScreen(image, **kwargs)
  File "C:\all_software\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 373, in locateOnScreen
    retVal = locate(image, screenshotIm, **kwargs)
  File "C:\all_software\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 353, in locate
    points = tuple(locateAll(needleImage, haystackImage, **kwargs))
  File "C:\all_software\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 253, in _locateAll_python
    raise NotImplementedError('The confidence keyword argument is only available if OpenCV is installed.')
NotImplementedError: The confidence keyword argument is only available if OpenCV is installed.

安装命令

由于opencv-python依赖numpy,所以会自动安装numpy

pip install opencv-python

你可能感兴趣的:(python,开发语言)