python - 在 Azure Synapse 笔记本中运行 nltk.download ValueError : I/O operation on closed file

标签 python jupyter-notebook nltk azure-synapse

我正在 Azure Synapse 笔记本中试验 NLTK。当我尝试运行 nltk.download('stopwords') 时,出现以下错误:

ValueError: I/O operation on closed file
Traceback (most recent call last):

  File "/home/trusted-service-user/cluster-env/env/lib/python3.6/site-packages/nltk/downloader.py", line 782, in download
    show(msg.message)

  File "/home/trusted-service-user/cluster-env/env/lib/python3.6/site-packages/nltk/downloader.py", line 775, in show
    subsequent_indent=prefix + prefix2 + " " * 4,

  File "/mnt/var/hadoop/tmp/nm-local-dir/usercache/trusted-service-user/appcache/application_1616860588116_0001/container_1616860588116_0001_01_000001/tmp/9026485902214290372", line 536, in write
    super(UnicodeDecodingStringIO, self).write(s)

ValueError: I/O operation on closed file
如果我尝试只运行 nltk.download() 我会收到以下错误:
EOFError: EOF when reading a line
Traceback (most recent call last):

  File "/home/trusted-service-user/cluster-env/env/lib/python3.6/site-packages/nltk/downloader.py", line 765, in download
    self._interactive_download()

  File "/home/trusted-service-user/cluster-env/env/lib/python3.6/site-packages/nltk/downloader.py", line 1117, in _interactive_download
    DownloaderShell(self).run()

  File "/home/trusted-service-user/cluster-env/env/lib/python3.6/site-packages/nltk/downloader.py", line 1143, in run
    user_input = input("Downloader> ").strip()

EOFError: EOF when reading a line
我希望有人可以就可能导致此问题的原因以及如何解决此问题给我一些帮助。我没能找到很多关于从这里去哪里的信息。
编辑:
我用来生成错误的代码如下:
import nltk
nltk.download('stopwords')
更新
我最终向 Microsoft 提出了支持请求,这是他们的回应:

Synapse does not support arbitrary shell scripts which is where you would download the related model corpus for NLTK


他们建议我使用 sc.addFile,我最终开始工作了。因此,如果其他人发现了这一点,这就是我所做的。
  • 在此处下载 NLTK 停用词:http://nltk.org/nltk_data/
  • 将停用词上传到存储中的以下文件夹:abfss://@.dfs.core.windows.net/synapse/workspaces//nltk_data/corpora/stopwords/
  • 运行以下代码以导入它们

  • .
    import os
    import sys
    import nltk
    from pyspark import SparkFiles
    
    #add stopwords from storage
    sc.addFile('abfss://<file_system>@<account_name>.dfs.core.windows.net/synapse/workspaces/<workspace_name>/nltk_data/',True)
    
    #append path to NLTK
    nltk.data.path.append(SparkFiles.getRootDirectory() + '/nltk_data')
    
    nltk.corpus.stopwords.words('english')
    
    谢谢!

    最佳答案

    我最终向 Microsoft 提出了支持请求,这是他们的回应:

    Synapse does not support arbitrary shell scripts which is where you would download the related model corpus for NLTK


    他们建议我使用 sc.addFile,我最终开始工作了。因此,如果其他人发现了这一点,这就是我所做的。
  • 在此处下载 NLTK 停用词:http://nltk.org/nltk_data/
  • 将停用词上传到存储中的 foll0woing 文件夹:abfss://@.dfs.core.windows.net/synapse/workspaces//nltk_data/corpora/stopwords/
  • 运行以下代码以导入它们

  • ....
    import os
    import sys
    import nltk
    from pyspark import SparkFiles
        
    #add stopwords from storage
        sc.addFile('abfss://<file_system>@<account_name>.dfs.core.windows.net/synapse/workspaces/<workspace_name>/nltk_data/',True)
        
    #append path to NLTK
    nltk.data.path.append(SparkFiles.getRootDirectory() + '/nltk_data')
        
    nltk.corpus.stopwords.words('english')
    
    谢谢!

    关于python - 在 Azure Synapse 笔记本中运行 nltk.download ValueError : I/O operation on closed file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66833402/

    相关文章:

    python - 如何在pandas数据框中的 `convert_objects`中产生异常

    python - 值错误: The truth value of a Series is ambiguous in one hot encoding error

    beautifulsoup - 安装了 BeautifulSoup 但仍然没有得到名为 bs4 的模块

    python - 如何计算 NLTK KMeans 聚类的准确度

    python-3.x - 如何POS_TAG法语句子?

    python - 如何在没有命令提示符窗口的情况下运行 wxPython 对话框?

    python - 如何在pygame中存储对象先前的x位置(坐标)?

    python - 没有名为 tensor flow 的模块——iPython notebook

    python - 从笔记本中清除 Jupyter 笔记本中单元格的小部件区域

    php - NLTK 找不到该文件