我刚刚通过pip安装了nltk,命令是:
sudo pip install -U nltk
我也以类似的方式立即安装了numpy,我尝试导入nltk并测试,在终端中键入'python'后键入'import nltk',然后得到了:
^{pr2}$我试图在网上找到解决方案,找到了这个链接Importing Libraries Issue - "ImportError: No Module named ____",
所以我尝试了这个命令:export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
,但是没有任何改变,可能是因为没有找到模块本身。我也试着使用命令
sudo pip install -U collocations
但上面写着
Collecting collocations
Could not find a version that satisfies the requirement collocations (from versions: )
No matching distribution found for collocations
当我第一次尝试的时候它也说 您使用的是pip版本8.1.1,但是版本9.0.1可用。 您应该考虑通过'pip install--upgrade pip'命令进行升级。在
我无法直接升级,但可以在使用时升级: sudo-H pip安装--升级pip
但我还是得到了同样的东西。我对python还很陌生,我想知道我是否做错了什么。我最近不得不重新安装Ubuntu16.04,所以我觉得操作系统运行得很好。非常感谢
编辑:所以有一个文件叫做nltk.py公司在我的主文件夹中,也许这会影响到这一点,我已经删除了这个文件,但是当我尝试导入nltk并打印与上面的回溯相同的内容时,它仍然以某种方式被创建。。。。 文件内容包括:
import sys
import nltk
from nltk.collocations import *
bigram_measures = nltk.collocations.BigramAssocMeasures()
trigram_measures = nltk.collocations.TrigramAssocMeasures()
# change this to read in your data
finder = BigramCollocationFinder.from_words(
nltk.corpus.genesis.words('annotation/dataset.txt'))
# only bigrams that appear 3+ times
finder.apply_freq_filter(3)
# return the 10 n-grams with the highest PMI
finder.nbest(bigram_measures.pmi, 10)
请使用
virtualenv
,因为如果您更新或安装python软件包global是不好的,因为ubuntu为自己的软件使用一些特殊的软件包版本,如果您更改了某些内容,可能会产生很多问题。您可以安装:这里有一个link很好地介绍了如何使用它。在
这可能也会解决你的问题。我自己也用Ubuntu16.04进行了测试。在
相关问题 更多 >
编程相关推荐