$ 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 find a version that satisfies the requirement pillow (from versions: ) No matching distribution found for pillow
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 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
curl https://bootstrap.pypa.io/get-pip.py | python
curl https://bootstrap.pypa.io/get-pip.py | python3
$ pip install pillow
Traceback (most recent call last): File "/Users/baorunchen/Documents/code/repo/python/advanced/image_recognition_test.py", line 29, in <module> main() File "/Users/baorunchen/Documents/code/repo/python/advanced/image_recognition_test.py", line 26, in main 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, in image_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, in run_and_get_output run_tesseract(**kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 111, in run_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: [Errno 2] No such file or directory
$ brew install tesseract
touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied touch: /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/.git/FETCH_HEAD: Permission denied touch: /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 config file .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 🍺 /usr/local/Cellar/tesseract/3.05.01: 79 files, 38.7MB
$ brew update $ sudo brew update $ brew upgrade $ brew cleanup $ brew install tesseract
$ brew link tesseract
Linking /usr/local/Cellar/tesseract/3.05.01... Error: Could not symlink share/man/man5/unicharambigs.5 /usr/local/share/man/man5 is not writable.
$ sudo chown ${USER} /usr/local/share/man/man5
pytesseract.pytesseract.tesseract_cmd = '<path-to-tesseract-bin>'
$ which tesseract
tesseract not found
/usr/local/bin/tesseract
pytesseract.pytesseract.tesseract_cmd = '/usr/local/bin/tesseract'
#!/usr/bin/env python # -*- coding: utf-8 -*- # @version: python 2.7.13 # @author: baorunchen(runchen0518@gmail.com) # @date: 2018/5/4 import os import time from PIL import Image import pytesseract pytesseract.pytesseract.tesseract_cmd = '/usr/local/bin/tesseract' pic_path = '/Users/baorunchen/Desktop/test.png' def run_log(log): print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '-', log def main(): if not os.path.exists(pic_path): run_log('pic not exists!') exit(-1) im = Image.open(pic_path) run_log(pytesseract.image_to_string(im)) if __name__ == '__main__': main()