在Windows中安装TextBlob

5 投票
5 回答
20996 浏览
提问于 2025-04-18 12:06

我按照这个链接中的说明 Trouble installing TextBlob for Python 在Windows 7上安装了TextBlob。虽然安装成功了,但当我打开Python的IDLE,输入 import TextBlob 时,却出现了

没有名为TextBlob的模块

我该怎么解决这个问题呢?

或者我可以直接把这个包相关的库放到Python的Lib文件夹里,然后在程序中尝试导入吗?如果这样做可行,请告诉我具体的步骤。这样做会有效吗?

任何帮助都将非常感谢。

5 个回答

0
conda install -c conda-forge textblob

这个在Jupyter环境中可以正常工作。

0

尝试一下

pip install textblob

如果你没有安装pip,可以在这里获取,pip非常有用哦。

3

在Windows系统中,如果你想安装textblob或者其他Python包,你需要给安装这些包的应用程序管理员权限。

我在用PyCharm安装的时候也遇到了同样的错误。我给了管理员权限,然后就顺利安装成功了!

pip install -U textblob
python -m textblob.download_corpora

要导入的话,只需输入:

from textblob import TextBlob

一个例子:

text = '''
The titular threat of The Blob has always struck me as the ultimate movie
monster: an insatiably hungry, amoeba-like mass able to penetrate
virtually any safeguard, capable of--as a doomed doctor chillingly
describes it--"assimilating flesh on contact.
Snide comparisons to gelatin be damned, it's a concept with the most
devastating of potential consequences, not unlike the grey goo scenario
proposed by technological theorists fearful of
artificial intelligence run rampant.
'''

blob = TextBlob(text)
blob.tags           # [('The', 'DT'), ('titular', 'JJ'),
                    #  ('threat', 'NN'), ('of', 'IN'), ...]

blob.noun_phrases   # WordList(['titular threat', 'blob',
                    #            'ultimate movie monster',
                    #            'amoeba-like mass', ...])

for sentence in blob.sentences:
    print(sentence.sentiment.polarity)
# 0.060
# -0.341

blob.translate(to="es")  # 'La amenaza titular de The Blob...'
3

试试这个:

from textblob import TextBlob

来源:TextBlob 包的介绍

4

用conda安装它。对我来说,这个方法有效!

conda install -c conda-forge textblob

撰写回答