GitHub 需要 NLTK "punkt" 时操作失败

GitHub Actions fails when NLTK "punkt" is needed

我写了一些代码,需要用到 NLTK 的 punkt。我已将 nltk 包含在 requirements.txtsetup.py 中。但是,当我 运行 使用 GitHub 操作构建我的项目时,它失败并出现此错误。

E       LookupError:   
E       **********************************************************************  
E         Resource punkt not found.  
E         Please use the NLTK Downloader to obtain the resource:  
E       
E         >>> import nltk  
E         >>> nltk.download('punkt') 

告诉 GitHub 操作它需要 'punkt' 而不硬编码 nltk.download('punkt') 代码某处的标准方法是什么? 我应该在 ci.yml 文件中添加一行吗?最好的方法是什么?

ci.yml 文件中,在导入 requirements.txt 中定义的依赖项后添加 nltk.downloader 命令行对我有用。

if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m nltk.downloader punkt stopwords