I installed NLTK, numpy and matplotlib but whenever I try running any code after importing NLTK an error appears saying that nltk is not a package. It doesn't give me any errors when i import nltk, it all happens after trying to import a text or a corpus. note I also tried on python shell, still not working
>>> import nltk
>>> from nltk.book import text1
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
from nltk.book import text1
ModuleNotFoundError: No module named 'nltk.book'; 'nltk' is not a package
nltk
library does not come by default with the corpses. You have to download these after importing nltk to access nltk.book
Try the following -
import nltk
nltk.download()
This will prompt you to download the relevant package contents, one of which is the nltk.book
that you are looking for -
NAME
nltk
PACKAGE CONTENTS
align
app (package)
book
ccg (package)
chat (package)
chunk (package)
classify (package)
cluster (package)
collocations
corpus (package)
data
decorators
downloader
draw (package)
examples (package)
featstruct
grammar
help
inference (package)
internals
lazyimport
metrics (package)
misc (package)
model (package)
parse (package)
probability
sem (package)
sourcedstring
stem (package)
tag (package)
test (package)
text
tokenize (package)
toolbox
tree
treetransforms
util
yamltags
FILE
c:\python32\lib\site-packages\nltk
More details here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.