python3安装nltk模块 Windows 64位下python3安装nltk模块

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

python3安装nltk模块 Windows 64位下python3安装nltk模块

llx1026   2021-03-30 我要评论

在网上找了各种安装教程,都没有在python3下安装nltk,于是我自己尝试着安装,算是成功了

1、首先,假设你的python3已经安装好,并且安装了numpy,matplotlib,pandas一些常用的库,当你安装nltk时,我相信你一定具备了一些python的常用技能,所以默认你已经安装了以上常用模块

2、然后,用cmd打开电脑终端,然后输入D:\Python362\Scripts\pip install pyyaml nltk,这样既安装了PyYAML模块,又安装了nltk模块

3、再次,在python3编辑器里输入import nltk按回车,如下图:

如这样你以为nltk就安装成功了那么你就大错特错了,因为还有一步,如果最后一步忽略的话,那么你在用nltk的时候会出现很多错误,具体出现什么样的错误,忘记截图了,后来运行成功后就没有错误了。

4、最后,在python3 shell里面输入一下命令:

按回车,然后就会出现如下窗口:

我是选择默认的下载路径,点击Download,静静的等待它下载完,关闭窗口。

下面进行nltk测试:

sent1 = 'The cat is walking in the bedroom'
sent2 = 'A dog was running across the kitchen'
 
from sklearn.feature_extraction.text import CountVectorizer
count_vec = CountVectorizer()
 
sentences = [sent1, sent2]
print(count_vec.fit_transform(sentences).toarray())
print(count_vec.get_feature_names())
 
import nltk
tokens_l = nltk.word_tokenize(sent1)
print(tokens_l)

运行结果如下:

[[0 1 1 0 1 1 0 0 2 1 0]
 [1 0 0 1 0 0 1 1 1 0 1]]
['across', 'bedroom', 'cat', 'dog', 'in', 'is', 'kitchen', 'running', 'the', 'walking', 'was']
['The', 'cat', 'is', 'walking', 'in', 'the', 'bedroom']

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们