python - 我在制作 pyautogui 程序时遇到了 windows 错误和 os 错误
问题描述
当我运行下面的代码时,我得到了这个错误:
文件“e:\pranil\python\doing shit with python\automating dino game.py”,第 12 行,在 if auto.pixelMatchesColor(i,j, (83, 83, 83)) 中:文件“C:\Users\ Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\site-packages\pyscreez__init__.py",第 559 行,在 pixelMatchesColor pix = pixel(x, y) 文件“C:\Users\Pranil .DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\site-packages\pyscreez__init__.py”,第 584 行,以像素返回 (r, g, b) 文件“C:\Users\Pranil. DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\contextlib.py",第 120 行,退出 next(self.gen) 文件“C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\site-packages\pyscreez__init__.py”,第 113 行,在 __win32_openDC 中引发 WindowsError( “windll.user32.ReleaseDC 失败:返回 0”)OSError:windll.user32.ReleaseDC 失败:返回 0
import pyautogui as auto
from PIL import Image, ImageColor
import time
import keyboard
auto.FAILSAFE = False
time.sleep(2)
# print(auto.position())
while True:
sshot = auto.screenshot()
for j in range(510, 514):
for i in range(316, 350):
if auto.pixelMatchesColor(i,j, (83, 83, 83)):
auto.press('up')
if keyboard.is_pressed('q'):
break
解决方案
我建议将你的 python 从 3.8 降级到 3.7,因为它为我解决了它。
推荐阅读
- html - 为什么 robots.txt 很重要?没有 robots.txt 的网站是否安全?
- facebook-graph-api - Leadgen Webhook:请求此资源需要用户访问令牌
- javascript - XSS 攻击和编码
- javascript - 导航器/窗口更改时如何更新反应钩子?
- keycloak - 无法从 keycloak 建立到 Mailhog 的 SMTP 连接
- java - java.lang.Error:java.lang.reflect.InvocationTargetException
- swift - HTTP POST html 数据有 0 个字节
- css - React Native Flex 不会填充宽度相等
- redis - 有什么理由在 Redis 中使用 multi/watch/exec 而不是 Lua 脚本(eval)?
- javascript - NEXT.js 如何在 redux 状态下同步服务器渲染的道具?