NLTK recently producing errors

I’ve been using NLTK package and been working fine but it started generating errors all of a sudden

code:


def Analyse (self):
  Filtered_Sent= anvil.server.call('NLP_Analysis',”Some test text”)

@anvil.server.callable  
def NLP_Analysis(Text):
  import nltk
  from nltk.corpus import stopwords  
  stop_words = nltk.corpus.stopwords.words('english')        
  filtered_Sent = [w for w in word_tokenize(Text) if w not in stop_words  ]
  return (' '.join(map(str, filtered_Sent)))

error:

Resource [93mpunkt [0m not found. Please use the NLTK Downloader to obtain the resource: [31m>>> import nltk >>> nltk.download(‘punkt’) [0m Attempted to load [93mtokenizers/punkt/PY3/english.pickle [0m Searched in: - ‘/anvil-shared/nltk-data’ - ‘/root/nltk_data’ - ‘/usr/local/nltk_data’ - ‘/usr/local/share/nltk_data’ - ‘/usr/local/lib/nltk_data’ - ‘/usr/share/nltk_data’ - ‘/usr/local/share/nltk_data’ - ‘/usr/lib/nltk_data’ - ‘/usr/local/lib/nltk_data’ - ‘’ ********************************************************************** at /usr/local/lib/python3.7/site-packages/nltk/data.py, line 699 called from /usr/local/lib/python3.7/site-packages/nltk/data.py, line 993 called from /usr/local/lib/python3.7/site-packages/nltk/data.py, line 868 called from /usr/local/lib/python3.7/site-packages/nltk/tokenize/init.py, line 104 called from /usr/local/lib/python3.7/site-packages/

Any advice is much appreciated

Thanks

Soadad

Hi @soadadfarhan,

According to that error message, nltk couldn’t find the punkt package, have you tried:

import nltk
nltk.download(‘punkt’)
from nltk.corpus import stopwords
...

Hi Ryan,

Many thanks for looking into this. Ian has been able to fix this issue for me.
I’ll close it now

Kind regards,

Soadad

1 Like

It’s working now.
Many thanks
Soadad