开发者

NLTK的安装教程及安装错误解决方案

开发者 https://www.devze.com 2023-04-17 09:20 出处:网络 作者: 安静到无声
目录成功解决NLTK包的安装错误NLTK的离线安装NLTK的验证成功解决NLTK包的安装错误
目录
  • 成功解决NLTK包的安装错误
  • NLTK的离线安装
  • NLTK的验证

成功解决NLTK包的安装错误

  1. 创建环境NLP_Pre_trainl环境
conda create -n NLP_Pre_train python=3.8 
  1. 激活
conda activate NLP_Pre_train 
  1. 安装NLTK,套用以下命令
pip install NLTK
  1. 之后是验证NLTK是否安装成功,采用的步骤如下所示:
import nltk  
nltk.download()

但是不出意外的是,很多人出现的错误,如下所示:

NLTK的安装教程及安装错误解决方案

为了解决此项问题,我们可以采用离线安装的方式进行解决。

NLTK的离线安装

  1. 首先现在离线安装包,我们直接去官网进行下载:https://github.com/nltk/nltk_data,安装的文件,如下所示:

NLTK的安装教程及安装错误解决方案

  1. 我们将下载的文件存放的位置如下所示

NLTK的安装教程及安装错误解决方案

  1. 我们将下载的以下文件文件,放进文件2所展示的位置,这样便大功告成!

NLTK的安装教程及安装错误解决方案

NLTK的验证

我们可以打印出,NLTK的英文停用词(STOP word)。

from nltk.corpus import stopwords  
print(stopwords.words('english'))

打印结果如下所示:

['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', "you're", 
"you've", "you'll", "you'd", 'your', 'yours', 'yourself', 'yourselves', 'he', 
'him', 'his', 'himself', 'she', "she's", 'her', 'hers', 'herself', 'it', "it's",
 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which',
  'who', 'whom', 'this', 'that', "that'll", 'these', 'those', 'am', 'is', 'are', 
  'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 
  'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 
  'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 
  'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 
  'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again',
   'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how',
   'all', 'any',开发者_C学习 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no',
    'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'tojZJykCo', 'very', 's', 't', 
    'can', 'will', 'just', 'don', "don't", 'should', "should've", 'now', 'd', 'll',
     'm', 'o', 're', 've', 'y', 'ain', 'aren', "aren't", 'couldn', "couldn't", 
     'didn', "didn't", 'doesn', "doesn't", 'hadn', "hadn't&quohttp://www.devze.comt;, 'hasn', "hasn't", 
     'haven', "haven't", www.devze.com'isn', "isn't", 'ma', 'mightn', "mightn&#http://www.devze.com39;t", 'mustn', 
     "mustn't", 'needn', "needn't", 'shan', "shan't", 'shouldn', "shouldn't", 
     'wasn', "wasn't", 'weren', "weren't", 'won', "won't", 'wouldn', "wouldn't&qjZJykCuot;

本文详细介绍了NLTK的安装方法和常见错误解决方案,对初学者很有帮助。另外,本文还对比了NLTK和其他自然语言处理工具的优缺点,为读者提供了选型参考。总的来说,NLTK是一款功能强大、易于使用的自然语言处理工具,值得学习和使用。

到此这篇关于NLTK的安装教程及安装错误解决方案的文章就介绍到这了,更多相关NLTK的安装内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号