[Python] Python NLTK: LookupError for 'averaged_perceptron_tagger_eng' after download

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm attempting to perform Part-of-Speech (POS) tagging in a Jupyter Notebook using the NLTK package. The averaged_perceptron_tagger resource cannot be located, according to the LookupError I keep receiving.

    The odd thing is that NLTK indicates the package is current even though I've already attempted to get it.

    I'm attempting to This is a simple illustration of the failing code:

    import nltk

    # I've also tried tokenizing with nltk.word_tokenize, but the error is the same.
    words = "Taj Mahal is a beautiful Monument".split()

    # This is the line that produces the error
    pos_tags = nltk.pos_tag(words)

    print(pos_tags)


    What I've attempted Downloading the resource directly: In a notebook cell, I executed the following command, and the result verified that the software had already been downloaded.

    import nltk
    nltk.download('averaged_perceptron_tagger')


    Output:

    [nltk_data] Downloading package averaged_perceptron_tagger to
    [nltk_data] C:\Users\aryan\AppData\Roaming\nltk_data...
    [nltk_data] Package averaged_perceptron_tagger is already up-to-
    [nltk_data] date!


    I also attempted to automatically handle the download by wrapping my code in a try...except block, but the code still fails with the same problem.

    The Mistake When I execute the code, I get the complete traceback as follows:

    LookupError Traceback (most recent call last)
    Cell In[16], line 1
    ----> 1 print(nltk.pos_tag("Taj Mahal is a beautiful Monument".split()))

    File ~\anaconda3\Lib\site-packages\nltk\tag\__init__.py:168, in pos_tag(tokens, tagset, lang)
    166 :rtype: list(tuple(str, str))
    167 """
    --> 168 tagger = _get_tagger(lang)
    169 return _pos_tag(tokens, tagset, tagger, lang)

    File ~\anaconda3\Lib\site-packages\nltk\tag\__init__.py:110, in _get_tagger(lang)
    108 tagger = PerceptronTagger(lang=lang)
    109 else:
    --> 110 tagger = PerceptronTagger()
    111 return tagger

    # ... (traceback continues) ...

    LookupError:
    **********************************************************************
    Resource averaged_perceptron_tagger_eng not found.
    Please use the NLTK Downloader to obtain the resource:

    >>> import nltk
    >>> nltk.download('averaged_perceptron_tagger_eng')

    For more information, see: https://www.nltk.org/data.html

    Attempted to load taggers/averaged_perceptron_tagger_eng/

    Searched in:
    - 'C:\\Users\\aryan/nltk_data'
    - 'C:\\Users\\aryan\\anaconda3\\nltk_data'
    - 'C:\\Users\\aryan\\anaconda3\\share\\nltk_data'
    - 'C:\\Users\\aryan\\anaconda3\\lib\\nltk_data'
    - 'C:\\Users\\aryan\\AppData\\Roaming\\nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    **********************************************************************


    Why does NLTK fail to find the resource even after I've downloaded it? How can I fix this LookupError in my environment?

    Thanks for your help!

    Continue reading...

Compartilhe esta Página