我试图将TextBlob导入Python。
当我直接在shell中运行命令时,它运行得很好: 来自textblob导入TextBlob
然而,当我把它放入py文件并运行它时,它不再起作用,它说:
ImportError: cannot import name 'TextBlob'
请帮帮我,现在非常绝望......非常感谢
答案 0 :(得分:2)
我遇到了同样的问题,通过在同一文件夹中删除以test *,text *开头的任何文件来解决它。
答案 1 :(得分:1)
我认为您的项目解释器和控制台的解释器可能有所不同。确保它们是相同的。
确保在项目解释器中安装了TextBlob。
答案 2 :(得分:0)
如果您在Windows上使用Pycharms,则需要以管理员身份打开pycharms。
如果您在Linux上安装它,那么sudo安装软件包。
答案 3 :(得分:0)
确保您没有任何名为text.py
的文件或文件夹。
如果
答案 4 :(得分:0)
1:导入应为:从textblob导入TextBlob(Python区分大小写,因此使用大写T和B导入TextBlob非常重要)
2:应该像这样安装textblob: Python2:
$ pip install -U textblob
$ python -m textblob.download_corpora
Python3:
$ pip3 install -U textblob
$ python3 -m textblob.download_corpora
答案 5 :(得分:-1)
我已经用pip命令安装了textblog:
sudo pip install textblob
我已经使用以下命令下载了语料库:
python -m textblob.download_corpora
这对textblob网站的例子很好。
以下是我使用命令运行的示例:./test.py
在我使用chmod +755 test.py
#!/usr/bin/env python
def test():
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...'
if __name__ == "__main__":
from textblob import TextBlob
test();