美文网首页自然语言处理(NLP)
PyInstaller提示错误"Unable to find "

PyInstaller提示错误"Unable to find "

作者: n美l美p | 来源:发表于2019-11-23 06:03 被阅读0次

PyInstaller的hook文件夹在处理nltk时会出现这样的错误,开发者的问题,跟我们没关系。我的电脑上使用的是pyinstaller-3.5。

现提供一种简单的解决办法:

1. 找到hook-nltk.py文件,通常此文件的目录为:

<PythonPath>/Lib/site-packages/PyInstaller/hooks/hook-nltk.py

在我的电脑上就是:

C:\Users\user\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PyInstaller\hooks\hook-nltk.py

2.修改此.py文件:

#-----------------------------------------------------------------------------
# Copyright (c) 2005-2019, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------


# hook for nltk
import nltk
from PyInstaller.utils.hooks import collect_data_files

# add datas for nltk
datas = collect_data_files('nltk', False)

# loop through the data directories and add them
# for p in nltk.data.path:
#     datas.append((p, "nltk_data"))

datas.append(("<path_to_nltk_data>", "nltk_data"))

# nltk.chunk.named_entity should be included
hiddenimports = ["nltk.chunk.named_entity"]

记住一定要把<path_to_nltk_data>替换成自己电脑上nltk_data文件夹所在的路径!

3. 修改后的.py文件:

在我的电脑上nltk_data文件夹的路径为:c:\users\user\appdata\roaming\nltk_data,所以修改后的hook-nltk.py为:

# hook for nltk
import nltk
from PyInstaller.utils.hooks import collect_data_files

# add datas for nltk
datas = collect_data_files('nltk', False)

# loop through the data directories and add them
#for p in nltk.data.path:
#    datas.append((p, "nltk_data"))

datas.append(("c:\\users\\user\\appdata\\roaming\\nltk_data", "nltk_data"))

# nltk.chunk.named_entity should be included
hiddenimports = ["nltk.chunk.named_entity"]

注意:用双斜杠表示文件夹路径!

若一时半会手动找不到nltk_data文件夹的路径,可使用两行python代码找到:

from nltk import data
print(data.find('.'))

相关文章

网友评论

    本文标题:PyInstaller提示错误"Unable to find "

    本文链接:https://www.haomeiwen.com/subject/jigkwctx.html