0

I am receiving the error "'nltk' is not a package" despite having downloaded it already. This is the exact message of the error:

"Traceback (most recent call last): File "/Users/parisvinuya/Dropbox/Mac/Desktop/chatbot - solicitor's website/chatbot-deployment/train.py", line 9, in from nltk_utils import bag_of_words, tokenize, stem File "/Users/parisvinuya/Dropbox/Mac/Desktop/chatbot - solicitor's website/chatbot-deployment/nltk_utils.py", line 4, in from nltk.stem.porter import PorterStemmer ModuleNotFoundError: No module named 'nltk.stem'; 'nltk' is not a package"

I receive this error despite attempting two different methods:

The first is I've installed the nltk package within venv:

$ (venv) python
>>> import nltk
>>> nltk.download('punkt')

I also found another solution on another stack overflow page: "https://stackoverflow.com/questions/38916452/nltk-download-ssl-certificate-verify-failed" where you apparently put this code inside another file and you run it. In this case I copy and pasted this code into a file called nltk.py to download nltk yet I still received the error...

import nltk
import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    pass
else:
    ssl._create_default_https_context = _create_unverified_https_context

nltk.download()

Also i've already installed 'pip install nltk'.

  • 1
    Have you checked this: https://stackoverflow.com/questions/40361488/importerror-no-module-named-nltk-tokenize-nltk-is-not-a-package ? The accepted answer there seems plausible for your case. – Anastasiia Iurshina Jun 06 '23 at 06:13
  • Is your file also named nltk? Have you tried renaming it? – Anna Jun 15 '23 at 17:06

0 Answers0