网络编程
位置:首页>> 网络编程>> Python编程>> Windows 64位下python3安装nltk模块

Windows 64位下python3安装nltk模块

作者:llx1026  发布时间:2023-11-20 09:42:12 

标签:python,python3,nltk

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

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

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

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

Windows 64位下python3安装nltk模块

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

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

Windows 64位下python3安装nltk模块

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

Windows 64位下python3安装nltk模块

我是选择默认的下载路径,点击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']

来源:https://blog.csdn.net/llx1026/article/details/78034238

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com