最近爬一个电影票房的网站(url:http://58921.com/alltime),上面总票房里面其实是一张图片,那么我需要把图片识别成文字,来获取票房数据。

我头脑里第一想到的解决方案就是要用tesseract3,别用2,经验来说3相比2,对中文的支持更好一点。

然后,我开始使用pip安装一系列相关的库:

$ pip install Pillow

$ pip install pytesser3

$ pip install pytesseract

第一步,首先执行:

$ pip install pillow

出现报错:

Collecting pillow

Could not fetch URL https://pypi.python.org/simple/pillow/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping

Could not finda version that satisfies the requirement pillow (from versions: )

No matching distribution foundfor pillow

截图如下:

我的第一反应是加个sudo,sudo pip install pillow来安装,出现同样报错,截图如下:

其实是pip的版本低了,然后我尝试更新pip版本,使用如下命令:

python -m pip install --upgrade pip

出现报错:

Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping

Requirement already up-to-date: pip in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

截图如下:

还是不行!

那么,换一种方式更新pip,命令如下:

$ pip install -U pip

还是出现报错:

Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping

Requirement already up-to-date: pip in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

截图如下:

再换一种更新pip,命令如下:

curl https://bootstrap.pypa.io/get-pip.py | python

注意一下后面,如果你是python3,那么:

curl https://bootstrap.pypa.io/get-pip.py | python3

终于可以了!

最终解决方案参考至:

然后安装pillow,命令如下:

$ pip install pillow

另外,建议使用pillow,PIL好多年前就停更了,现在pillow fork过来,然后一直在维护。

现在可以使用最新的pip批量安装上述的库了。

后来写了一个test.py,发现使用pytesseract.image_to_string()函数时,报下面的崩溃:

Traceback (most recent call last):

File"/Users/baorunchen/Documents/code/repo/python/advanced/image_recognition_test.py", line 29, in main()

File"/Users/baorunchen/Documents/code/repo/python/advanced/image_recognition_test.py", line 26, inmain

run_log(pytesseract.image_to_string(im))

File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 193, inimage_to_string

return run_and_get_output(image,'txt', lang, config, nice)

File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 140, inrun_and_get_output

run_tesseract(**kwargs)

File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 111, inrun_tesseract

proc= subprocess.Popen(command, stderr=subprocess.PIPE)

File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 390, in__init__

errread, errwrite)

File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1024, in_execute_child

raise child_exception

OSError: [Errno2] No such file or directory

截图如下:

原因是:安装Tesseract-OCR后,其不会被默认添加至环境变量path中,已导致报错;

解决这个问题可参考网址:

解决方案:

先需要在mac环境上安装tesseract这个库:

$ brew install tesseract

又报错了,如下:

touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission deniedtouch: /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/.git/FETCH_HEAD: Permission deniedtouch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/FETCH_HEAD: Permission denied

fatal: Unable to create'/usr/local/Homebrew/.git/index.lock': Permission denied

error: could not lock configfile .git/config: Permission denied==> Downloading https://homebrew.bintray.com/bottles/tesseract-3.05.01.high_sierra.bottle.tar.gz

Already downloaded: /Users/baorunchen/Library/Caches/Homebrew/tesseract-3.05.01.high_sierra.bottle.tar.gz==> Pouring tesseract-3.05.01.high_sierra.bottle.tar.gz

Error: The `brew link` step did not complete successfully

The formula built, but is not symlinked into/usr/local

Could not symlink share/man/man1/ambiguous_words.1

/usr/local/share/man/man1 is not writable.

You can try again using:

brew link tesseract==>Summary

python pillow环境_解决Python图片处理模块pillow使用中出现的问题相关推荐

  1. anaconda新建不同python版本环境_解决 Anaconda 与 ROS 冲突(python 版本与 opencv)

    1. Python 版本冲突 默认情况下,用 catkin_make 编译 ros 工作空间,依赖于 pyhton2.7,若在终端中输入 python,进入 python2.7 的环境,则没什么问题. ...

  2. python使用环境_使用python之环境管理

    情景1:不同python版本的管理 同一电脑上的多个python版本之前的管理,为了突出问题的普遍存在,下面是有人在segmentfault上提的问题. 摘自:http://segmentfault. ...

  3. python脚本限制_解决python 上传图片限制格式问题

    终于忙完有空更新了,这次说下一个比较简单的东西,限制上传图片格式问题. 先上代码! img_file = 'D:\\image\\test.jpg' # uuid生成文件名 key = shortuu ...

  4. 安卓手机python开发环境_使用Python开发Android应用程序:第一节 在手机上配置Python运行环境...

    本节目录: 1.下载和安装 Scripting Layer for Android (SL4A) 2.下载和安装 Python for android 3.第一个HelloWorld程序 1.下载和安 ...

  5. 认识python编程环境_认识Python和安装Python环境

    学习目标: 1. 了解什么是Python?为什么学习Python?Python都可以做什么? 2. 了解并安装Python环境,体验第一Python程序. 学习内容: 1.什么是Python? Pyt ...

  6. python super 多重继承_解决python super()调用多重继承函数的问题

    当类间继承关系很简单时,super()的使用很简单. class A(object): def __init__(self): print('a') class B(A): def __init__( ...

  7. python中幂函数_解决python中的幂函数、指数函数问题

    最近在调代码,碰到幂函数.指数函数,总是提示 ValueError: math domain error ValueError: negative number cannot be raised to ...

  8. 阿里云服务器搭建python web环境_《Python入门》Linux 下 Python Web开发环境搭建笔记-阿里云开发者社区...

    之前写过 Windows 7下Python Web开发环境搭建笔记,今天写一下在Linux系统下搭建Python Web的开发测试环境. 我使用的系统是:ubuntu 14.04 server,根据个 ...

  9. 在线的python运行环境_在线Python环境(Azure Notebooks)

    前言 上文说道了anaconda的安装和使用.对于动手能力较差的小伙伴们来说,安装还是太过麻烦,一出现问题也不知道如何查错,然后就从入门选择放弃. 说起编程的两个拦路虎,一个就是环境配置,另一个就是编 ...

最新文章

  1. 使用postman修改SAP Marketing Cloud contact主数据
  2. 字节跳动凌晨发半个月奖金,网友:我酸了,又是别人家的公司!
  3. python编程入门 电子书-Python编程从入门到实践PDF电子书
  4. C语言字符串做函数参数
  5. Openstack 一直在调度中解决
  6. 灯效控制器和rgb控制器_更具个性的RGB风扇,机箱里的魔术师,九州风神MF120GT开箱...
  7. php zhxing iptables,Linux iptables 扩展 ipset 使用教程
  8. Codejock Xtreme ToolkitPro MFC 使用
  9. blob 在线解码_一款支持在线的磁力播放工具
  10. Pyserial安装
  11. 移动硬盘插入提示需要格式化RAW_移动硬盘数据恢复 – 图文教程
  12. docker中的localhost
  13. 逐点插入法-delaunay三角剖分
  14. Redis解决缓存雪崩和缓存穿透
  15. 【数字设计】联发科技_笔试面试题目分享
  16. vb计算机 小数前没有0,VB 小于1的小数 显示不出来小数点前的0 大哥帮忙
  17. 百度涉嫌干涉以色列广播虚假新闻被黑
  18. 统一登录验证统一返回格式统一异常处理的实现
  19. 步步扎进Java-泛型与集合
  20. C++调用win32 API操作打印机实现驱动打印

热门文章

  1. 如果你需要万圣节的图片素材来点缀你的节日活动,看这里就对了
  2. 帮助UI设计师缕清思路的GUI模板素材
  3. python add_subplot_Python使用add_subplot与subplot画子图操作
  4. python语言中最基本的概念_Python 学习之路-基本的概念(三)
  5. QT打开文件选择框(demo code)
  6. CUDA零拷贝内存(zerocopy memory)
  7. Python OOP:面向对象基础,定义类,创建对象/实例,self,创建多个对象,添加对象属性,访问对象属性,__init__方法,带参数的__init__,__str__方法,__del__方法
  8. adprw指令通讯案例_实例 | 三菱FX3U485无协议通讯程序详解(含程序)
  9. sklearn之kmean(无监督聚类)
  10. windows vs编译环境 python_Python虚拟环境使用(Windows)