【问题标题】:GitHub Actions fails when NLTK "punkt" is needed需要 NLTK“punkt”时 GitHub Actions 失败
【发布时间】:2020-09-25 12:48:37
【问题描述】:

我已经编写了一些需要使用 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 文件中添加一行,最好的方法是什么?

【问题讨论】:

  • 我找到了一种解决方法,方法是在使用 pytest 运行测试之前将echo -e "import nltk\nnltk.download('punkt')" | python3 添加到ci.yml。但是,任何更优雅的解决方案都非常受欢迎。
  • 尝试创建 nltk.txt 文件并包含 punkt?
  • 也只是使用了 andrea 提出的 ci.yml 更改。似乎正在工作:D

标签: python continuous-integration nltk github-actions building-github-actions


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 2020-07-19
    • 2021-05-02
    • 2021-08-18
    • 2021-04-23
    • 2021-05-07
    • 2020-03-26
    相关资源
    最近更新 更多