首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Python: 升级pillow模块

Python: 升级pillow模块

作者头像
Exploring
发布2022-08-10 09:10:16
发布2022-08-10 09:10:16
2.2K0
举报

文章背景:最近在学习pyautogui模块中的处理屏幕,想要通过运行python代码,获取鼠标光标处像素的RGB颜色值。python代码如下:

代码语言:javascript
复制
# from the book: Automate the Boring Stuff with Python
import pyautogui
pyautogui.pause = 1
pyautogui.failsafe = True

print('Press Ctrl-C to quit.')
try:
    while True:
        # Get and print the mouse coordinates.
        x, y = pyautogui.position()
        positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
        
        pixelColor = pyautogui.screenshot().getpixel((x,y))
        positionStr += ' RGB: (' + str(pixelColor[0]).rjust(3)
        positionStr += ', ' + str(pixelColor[1]).rjust(3)
        positionStr += ', ' + str(pixelColor[2]).rjust(3) + ')'
        print(positionStr,end = '')
        print('\b'*len(positionStr),end='',flush = True)
except KeyboardInterrupt:
    print('\nDone.')

代码运行时,程序报错。pyscreeze.PyScreezeException: The Pillow package is required to use this function.

检查电脑上的pyllow模块,目前是6.2.0版本,还不是最新版本,考虑升级pyllow模块。我的电脑环境是:win10+py3.7+anaconda3。在Anaconda3的Prompt上运行如下代码:

pip install -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com pillow

也就是说,豆瓣源上的pillow模块是6.2.0版本,而pypi.org网站上最新的pillow模块是7.2.0版本。后来在网上找到了清华大学源。在Anaconda3的Prompt上运行如下代码:

pip install -U pillow -i https://pypi.tuna.tsinghua.edu.cn/simple/

Pillow-7.2.0安装成功。

重新运行前面的python代码,不再报错。

视频演示:http://mpvideo.qpic.cn/0bf2l4bgwaaciuag6dj3mrpvex6dnnpqe2ya.f10002.mp4?

参考资料:

  1. pip通过国内源快速安装包(https://ddz.red/CTePo
  2. Automate the Boring Stuff with Python(https://ddz.red/y9qF5
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-08-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 数据处理与编程实践 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档