赞
踩
直接进入anaconda的命令行用pip install gensim安装,报错了,之后又查阅了各种资料,最终成功安装了gensim包,在此记录一下过程。
先说明以下我的anaconda虚拟环境的配置,我是在pytorch gpu 1.8.0版本下安装的,python是3.6版本,win10系统,64位。我安装的是gensim4.1.0,numpy是1.19.5(注意:gensim4.1.0要求numpy版本>=1.17.0)。
pip install gensim安装不成功,我便采用了离线安装的方法,即先从官网上下载安装包,然后在命令行对安装包进行安装。具体步骤如下:
1、先在anaconda虚拟环境中安装一些需要的依赖包,有numpy、scipy、six、smart_open、python——dateutil,就简单地用 pip install 安装即可。
2、去gensim官网下载gensim4.1.0,具体版本可以根据你的python版本及需要选择,我这里选择的下图红框中的。
3、在anaconda prompt中将路径定位到gensim安装包的位置,然后输入:
pip install gensim-4.1.0-cp36-cp36m-win_amd64.whl
(后面的gensim……可以按tab键自动补全)进行安装。
4、在pycharm进行测试,输入以下代码:
- from gensim import corpora,models,downloader,similarities
- from collections import defaultdict
- documents = ["Human machine interface for lab abc computer applications",
- "A survey of user opinion of computer system response time",
- "The EPS user interface management system",
- "System and human system engineering testing of EPS",
- "Relation of user perceived response time to error measurement",
- "The generation of random binary unordered trees",
- "The intersection graph of paths in trees",
- "Graph minors IV Widths of trees and well quasi ordering",
- "Graph minors A survey"]
-
- # 去掉停用词
- stoplist = set('for a of the and to in'.split())
- texts = [[word for word in document.lower().split() if word not in stoplist]
- for document in documents]
- print(texts)
可以得到以下输出,即说明gensim安装成功。
[['human', 'machine', 'interface', 'lab', 'abc', 'computer', 'applications'], ['survey', 'user', 'opinion', 'computer', 'system', 'response', 'time'], ['eps', 'user', 'interface', 'management', 'system'], ['system', 'human', 'system', 'engineering', 'testing', 'eps'], ['relation', 'user', 'perceived', 'response', 'time', 'error', 'measurement'], ['generation', 'random', 'binary', 'unordered', 'trees'], ['intersection', 'graph', 'paths', 'trees'], ['graph', 'minors', 'iv', 'widths', 'trees', 'well', 'quasi', 'ordering'], ['graph', 'minors', 'survey']]
到此,gensim库的安装就完成了!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。