Python2.7.17 PyAutoGUI说枕头没有安装,但是已经安装了

2024-06-09 04:24:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在制作一个应用程序,可以截图并比较其中的一些内容。现在,在很长一段时间之后,我设法得到了一个与以前不同的错误,在程序中更进一步(万岁进步!)

我已经发布了回溯,其中说枕头包是必需的,但它已经与PyAutoGUI一起安装。我已经安装了以前的版本,希望它能解决这个问题。它没有

我正在Windows XP上制作32位(是的,我知道,它在5年前已经达到了EOL,但目标计算机有WinXP

以下是我安装的所有软件包的列表:

Package     Version
----------- -------
MouseInfo   0.1.2
numpy       1.16.6
Pillow      6.0.0
pip         20.0.2
PyAutoGUI   0.9.48
PyGetWindow 0.0.8
PyMsgBox    1.0.7
pyperclip   1.7.0
PyRect      0.1.4
PyScreeze   0.1.26
PyTweening  1.0.3
setuptools  41.2.0

你们能帮帮我吗

代码:

# Standard imports
import cv2
import numpy as np
import time
import pyautogui
import datetime
import time

global LatestLine

# Square 1 Coordinates - Check if machine is working
x1=280
y1=55
h1=31
w1=33
# Square 2 Coordinates - Check if program is active
x2=157
y2=177
h2=38
w2=38

while True:
    #Get Screenshot
    imagem = pyautogui.screenshot()
    imagem.save(r'C:/Machine_Tracker/Imagem_Moving.png')

    print ("Screenshot taken")

    #Set image
    imagem = cv2.imread("C:/Machine_Tracker/Imagem_Moving.png", cv2.IMREAD_GRAYSCALE)
    im = cv2.bitwise_not(imagem)

    now = datetime.datetime.now() 
    # Read square 1 - Check if machine is working
    print "Crop image to check if machine is working"
    crop_img = im[y1:y1+h1, x1:x1+w1]
    n_white_pix1 = np.sum(crop_img == 255)
    print('Number of white pixels:', n_white_pix1)
    #cv2.imshow("Machine Status: White Pixels: {0}".format(n_white_pix1), crop_img)
    cv2.imwrite("C:/Machine_Tracker/Machine_Status/MachineStatus.png", crop_img)

    # Read square 2 - Check if program is active
    print "Crop image to check if program is active"
    crop_img = im[y2:y2+h2, x2:x2+w2]
    n_white_pix2 = np.sum(crop_img == 255)
    print('Number of white pixels:', n_white_pix2)
    #cv2.imshow("Program Status: White Pixels: {0}".format(n_white_pix2), crop_img)
    cv2.imwrite("C:/Machine_Tracker/App_Status/AppStatus.png", crop_img)

    #Se Estiver na app
        # Se Estiver a trabalhar
            #Escreve "Working + DateTime"
        # Else
            #Escreve "Not Working + DateTime"
        #EndIf
    # Else
        #Escreve "Fora Da App + Datetime"
    #endif

    if n_white_pix2 == 608: #Esta na app
        if n_white_pix1 <= 1023: #Esta a trabalhar
            #Quando a maquina nao esta a trabalhar,
            #o bocado que vamos buscar tem 1023 pixeis brancos
            #Sempre que e menor que esse valor, a maquina esta a trabalhar
            #Write machine working log to file
            Log = open("C:/Machine_Tracker/StatusLog.txt", "w")
            LatestLine = "{0} - App is open and Machine is working\n".format(now.strftime("%Y-%m-%d %H:%M:%S"))
            Log.write(LatestLine)
            Log.close()
            #print LatestLine
            print(LatestLine)
        else:
            #Write machine working log to file
            Log = open("C:/Machine_Tracker/StatusLog.txt", "w")
            LatestLine = "{0} - App is open but Machine is NOT working\n".format(now.strftime("%Y-%m-%d %H:%M:%S"))
            Log.write(LatestLine)
            Log.close()
            print(LatestLine)
    else:
        #Write machine working log to file
        Log = open("C:/Machine_Tracker/StatusLog.txt", "w")
        LatestLine = "{0} - App is NOT open\n".format(now.strftime("%Y-%m-%d %H:%M:%S"))
        Log.write(LatestLine)
        Log.close()
        print(LatestLine)

    time.sleep(20)
cv2.waitKey(0)

回溯:

Traceback (most recent call last):
  File "C:\Python27\Check_for_Status.py", line 24, in <module>
    imagem = pyautogui.screenshot()
  File "C:\Python27\lib\site-packages\pyscreeze\__init__.py", line 134, in wrapper
    raise PyScreezeException('The Pillow package is required to use this function.')
PyScreezeException: The Pillow package is required to use this function.

Tags: tocropimportlogimgifismachine
2条回答

也许您应该尝试在python代码中导入枕头???我不确定,但请尽量在顶部包含以下内容:

import Pillow

尝试在命令Propmpt中运行

import PIL
import pyautogui
pyautogui.screenshot()

相关问题 更多 >