Hello, nice to meet you, good night. I'm sorry.
The information available in this article is:
--If you are using pyocr and packaging with pyinstaller, remove the WARNING that appears. --tesseract-How to distribute exe using OCR / pyocr
Install Tesseract-OCR separately (Teacher! I think this is the number one cause!)
Write * .py with the appropriate pyocr
pyinstaller hoge.py
When you start foo.exe spit out with dist, the following log is output ...
Running from container, but no tessdata (C:\Users\{user}\AppData\Local\Temp\_MEI{tempnumber}\data) found !
Running from container, but no tessdata (C:\Users\{user}\AppData\Local\Temp\_MEI{tempnumber}\data) found !
Well, even if this happens, if Tesseract-OCR is installed separately on the target PC, it can be executed, so there are not many people who are fundamentally in trouble ...
However, since it is dirty, I will erase it.
If you glance inside pyocr, you will find it near Line: 120 in tesseract.py.
This is the cause.
if getattr(sys, 'frozen', False): # pragma: no cover
# Pyinstaller support
path = os.environ["PATH"]
if sys._MEIPASS in path:
# already changed
return
tesspath = os.path.join(sys._MEIPASS, "tesseract")
tessprefix = os.path.join(sys._MEIPASS, "data")
logger.info("Running in packaged environment")
if not os.path.exists(os.path.join(tessprefix, "tessdata")):
logger.warning(
"Running from container, but no tessdata ({}) found !".format(
tessprefix
)
)
else:
logger.info("TESSDATA_PREFIX set to [{}]".format(tessprefix))
os.environ['TESSDATA_PREFIX'] = tessprefix
if not os.path.exists(tesspath):
logger.warning(
"Running from container, but no tesseract ({}) found !".format(
tesspath
)
)
else:
logger.info("[{}] added to PATH".format(tesspath))
os.environ['PATH'] = (
tesspath + os.pathsep + os.environ['PATH']
)
It seems that they are doing various things, but the user does not know this (crying)
Apparently it would be nice if sys._MEIPASS had tesseract and data.
Then you can add tesseract and data to sys._MEIPASS! Solution! Enthusiasm! READY to FIGHT!
Add the following to * .spec
Tree('{Tesseract-OCR path}',prefix='tesseract'),
Tree('{Tesseract-OCR path}',prefix='data'),
Running from container, but no tessdata (C:\Users\{user}\AppData\Local\Temp\_MEI{tempnumber}\data) found !
Running from container, but no tessdata (C:\Users\{user}\AppData\Local\Temp\_MEI{tempnumber}\data) found !
It seems that the fighting power is still insufficient.
Eventually it became like this.
I have to have more tessdata in the data, and I don't understand the meaning because the contents are duplicated. (Maybe there is a better solution ...)
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['{main}.py'],
pathex=['{src_dir}'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
Tree('{data}',prefix='data'),
Tree('{tesseract}',prefix='tesseract'),
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='{appname}',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True , icon='icon.ico')
There is no change here.
{main}.py {} .py No special description required
pyinstaller! Now that you're ready
$> pyinstaller --onefile --clean --icon={icon}.ico -n {appname} {main}.py
And make {appname} .spec as above
$> pyinstaller {appname}.spec
And distribute {appname} .exe under dist and it's okay!
This is just a Windows environment method, but of course you do not need to install Tesseract-OCR separately on the target PC.
If there is a better way, I would appreciate it if you could teach me in the reply on Twitter or in the comments here!
Then Otonoshi
Recommended Posts