FileNotFoundError: [Errno 2] No such file or directory...‘C:\\Users\\ADMIN...MEI15052jieba\\dict.txt

pyinstaller packages the exe file, and it flashes when it is executed. I used alt+pyt scr to capture the screen and saw an error:

FileNotFoundError: [Errno 2] No such file or directory...'C:\\Users\\ADMIN...MEI15052jieba\\dict.txt

As shown in the figure below: After
Insert picture description here
searching hard, I finally found the god-man.

Reason: The dict.txt of the python library jieba was not packaged in, which caused an error.
Solution:
Write a hook by yourself, and then put it into the hooks of pyinstaller.
The naming convention of the hook file is: hook-[library name].py. Take the stuttering word segmentation as an example, that is, hook-jieba.py. There are only two codes. OK, as shown in the figure below:

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files("jieba")

The hooks folder of pyinstaller is probably located at:

python root directory\Lib\site-packages\PyInstaller\hooks,

Then throw hook-jieba.py in, as shown below:
Insert picture description here

Finally, go back to the project root directory and package it with pyinstaller. (Note that you may need to delete the build directory to make pyinstaller package from scratch)

From

Guess you like

Origin blog.csdn.net/weixin_47542175/article/details/114192471