#3928·nltk

WordNet 语料库被报告为已下载,但 WordNetLemmatizer 无法找到

作者: knkn464创建于 2026年9月29日更新于 2026年9月29日

**环境** - 操作系统: Linux 容器 - Python: 3.11.x - NLTK: 3.10.3 - 安装方法: pip - 运行时: Nuclio/Kubernetes - 语料库下载目录: `/usr/local/lib/nltk_data` **问题** `wordnet` 在 Docker 镜像构建期间已被下载,但服务容器在运行时失败,错误如下: `LookupError: Resource wordnet not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download('wordnet')` **预期行为** 在下载 wordnet 之后,应成功执行: WordNetLemmatizer().lemmatize("bearings") **预期输出:** bearing **实际行为** 容器在应用程序初始化期间失败 `LookupError: Resource 'wordnet' not found File ".../nltk/corpus/util.py", line ... raise e` 以下是构建日志: `#11 [6/9] RUN Python -m nltk.downloader -d /usr/local/lib/nltk_data stopwords #11 1.335 <frozen runpy>:128: RuntimeWarning: 'nltk.downloader' found in sys.modules after import of package 'nltk', but prior to execution of 'nltk.downloader'; this may result in unpredictable behaviour #11 1.386 [nltk_data] Downloading package stopwords to /usr/local/lib/nltk_data... #11 1.421 [nltk_data] Unzipping corpora/stopwords.zip. #11 DONE 1.6s #12 [7/9] RUN Python -m nltk.downloader -d /usr/local/lib/nltk_data wordnet #12 1.020 <frozen runpy>:128: RuntimeWarning: 'nltk.downloader' found in sys.modules after import of package 'nltk', but prior to execution of 'nltk.downloader'; this may result in unpredictable behaviour #12 1.064 [nltk_data] Downloading package wordnet to /usr/local/lib/nltk_data... #12 DONE 1.3s #13 [8/9] RUN Python -m nltk.downloader -d /usr/local/lib/nltk_data omw-1.4 #13 1.075 <frozen runpy>:128: RuntimeWarning: 'nltk.downloader' found in sys.modules after import of package 'nltk', but prior to execution of 'nltk.downloader'; this may result in unpredictable behaviour #13 1.117 [nltk_data] Downloading package omw-1.4 to /usr/local/lib/nltk_data... #13 DONE 1.4s` 下面是错误日志: <img width="967" height="487" alt="Image" src="https://GitHub.com/user-attachments/assets/e12e8d6b-abf0-41cb-9c8e-592b75ce2e90" />