Resolved ModuleNotFoundError: No module named 'nltk'



Resolved ModuleNotFoundError: No module named 'nltk'













error code



A small friend in the fan group used Python to run the program to read the nltk thesaurus, but an error occurred (at that time, he felt a lot of cold in his heart, and he came to me for help, and then successfully helped him solve it. By the way, I hope it can help more Many friends who encounter this bug will not solve it), the error message is as follows:


import nltk
from nltk.corpus import brown # 需要下载brown语料库
# 引用布朗大学的语料库

# 查看语料库包含的类别
print(brown.categories())

# 查看brown语料库
print('共有{}个句子'.format(len(brown.sents())))
print('共有{}个单词'.format(len(brown.words())))

Screenshot of error message :

insert image description here





error translation



Error message translation :

Module not found error: No module named 'nltk'



Reason for error



Reason for the error :


Fans directly copy other people's code on the Internet, but do not install the required third-party modules, so the program will report an error.Friends, execute the following installation commands! ! !





Solution



Execute the following pip command to install the module:

pip install nltk

insert image description here

After installation, you can see that there is no problem with the guide package:

insert image description here



help



This article has been included in: "Farewell to Bug" column

This column is used to record various difficult bugs encountered in study and work, as well as various problems raised by small partners in the fan group. Article format: error code + error translation + error reason + solution, including program installation, operation If you encounter other problems in the process of the program, if you encounter other problems after subscribing to the column + following the blogger, you can privately chat to help solve them! ! !

Guess you like

Origin blog.csdn.net/yuan2019035055/article/details/126400313