【问题标题】:nltk_data installation gives RuntimeWarningnltk_data 安装给出 RuntimeWarning
【发布时间】:2021-11-25 20:00:34
【问题描述】:
python3 -m nltk.downloader -d /usr/local/share/nltk_data all

在 GCP 中运行上述命令后,我遇到以下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

我也已经安装了 nltk。在安装它时,我必须添加 --proxy 开关。我假设我也需要在这里进行代理切换,所以这里有可能是问题所在。但我不知道如何在此处添加代理开关。

【问题讨论】:

    标签: python python-3.x google-cloud-platform nltk


    【解决方案1】:

    我创建了一个 GCE 实例来安装 NLTK 并测试您包含的命令,它显示了相同的警告消息。根据 NLTK Github repository 中的这个问题,由于在 __init__.py 文件中导入模块的方式,会出现警告消息。 NLTK 开发人员解释说,重构模块会破坏向后兼容性。引用注释 here 时,警告消息似乎是一个已知问题并且无害。

    如果您想隐藏警告消息,可以使用 Python 中的 -W switch,如下所示:

    python3 -W ignore -m nltk.downloader -d ./nltk.data all
    

    另一种选择是在Python单行脚本中先手动导入NLTK,使用-c开关(参数是要下载的包,可以在their documentation中引用):

    python3 -c “import nltk; nltk.download(‘all’)”
    
    RUN python3 -c “import nltk; nltk.download(‘all’)” # When running from a Dockerfile
    

    我在 GCE 实例中测试了这两个选项,但没有看到警告消息。本文档是 GCP 的外部文档,因此我无法保证其准确性。

    【讨论】:

    • 感谢您的详细回复,我试试这个(:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 2018-12-22
    • 2017-11-24
    • 1970-01-01
    • 2022-06-15
    相关资源
    最近更新 更多