1. 程式人生 > >造新輪子啦,讓pytesser支持3.x啦~

造新輪子啦,讓pytesser支持3.x啦~

all 源碼 too 默認安裝 直接 print 很多 tab gmail

http://www.songluyi.com/%E9%80%A0%E6%96%B0%E8%BD%AE%E5%AD%90%E5%95%A6%EF%BC%8C%E8%AE%A9pytesser%E6%94%AF%E6%8C%813-x%E5%95%A6/

0x00 前言

曾經用2.x版本的Python寫過一個小小的驗證碼識別小程序,不到三十行,用的是pytesser 但是pytesser僅僅支持2.x版本,因此我們需要將這個輪子改寫為3.x,方便我們調用。

等不及的小夥伴可以直接pip install pytesser3 即可完成輪子的安裝

0x01 改寫的時候遇到的坑

第一坑:

很多2.x能用 而3.x不能用的情況發生,比如引用的包發生改變 (import PIL 改為from PIL import Image) print 改變 except 一些修改,改好了以後,才到了 這個傻逼包內置的tessract用不了的問題,你需要自己安裝Google 的圖像識別引擎:Tesseract OCR

網上有exe安裝包 我這裏為了方便大家就提供一下下載地址。

第二坑:

pypi打包的坑,本文重點是這個。

  1. 技術分享圖片這是我的目錄大綱,一級是pytesser3 和一些readme setup.py文件 二級是__init__.py等py文件 ,不過還有一些其他的如圖片文件 tif 字體文件,在二級目錄還包含著 三級目錄 等 那我是這麽做呢可以看一下下面我的代碼

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 from setuptools import setup, find_packages
setup( name = ‘pytesser3‘, version = ‘1.0.1‘, keywords = (‘pytesser‘, ‘support 3.x‘), description = ‘modify and let it support 3.x‘, license = ‘MIT License‘, install_requires = [‘requests‘], author = ‘LouisSong‘, author_email = [email protected], packages = find_packages(),
package_data = { # If any package contains *.txt files, include them: ‘‘: [‘*‘,‘tressdata/*],#看這裏就好啦,就可以吧裏面的都包含進來 # And include any *.dat files found in the ‘data‘ subdirectory # of the ‘mypkg‘ package, also: }, platforms = ‘any‘, )

  1. 第二個坑,網上都喜歡一個二個的告訴我說 先去官網pypi註冊一下,然後運行

    python setup.py register

    但是我運行了一會,就報錯說需要byte like 不是str 請看源碼 我本身就造了一個輪子心情好得很 我還要再造一個麽肯定不行,那就換一個上傳工具 我們先安裝twine 然後運行一下代碼即可

    1 twine upload -r pypi dist/*

我自己測試了一下 可以用 pip install pytesser3,如圖

技術分享圖片

同時內置code.py 檢測這個輪子是否好用

技術分享圖片

需要註意的是,務必安裝google的Tesseract OCR 最好默認安裝 謝謝

另外:PIL這個坑自己去踩,謝謝~

源碼地址:

https://github.com/songluyi/pytesser3

期待你的star

造新輪子啦,讓pytesser支持3.x啦~