温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

NLTK安装错误怎么解决

发布时间:2023-04-17 16:19:32 阅读:371 作者:iii 栏目:开发技术
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

今天小编给大家分享一下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''both''each''few''more''most''other''some''such''no',
    'nor''not''only''own''same''so''than''too''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"'hasn'"hasn't", 
     'haven'"haven't"'isn'"isn't"'ma''mightn'"mightn'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"

以上就是“NLTK安装错误怎么解决”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

原文链接:https://blog.51cto.com/lihuanyu/6192618

AI

开发者交流群×