2

TextBlob を Python にインポートしようとしていました。

コマンドをシェル内で直接実行すると、かなりうまく機能します。 from textblob import TextBlob

ただし、それをpyファイルに入れて実行すると、もう機能しません。

ImportError: cannot import name 'TextBlob'

私を助けてください、今とても必死です...どうもありがとう

4

7 に答える 7

0

Windows で Pycharms を使用している場合は、管理者として pycharms を開く必要があります。

Linux にインストールする場合は、sudo でパッケージをインストールします。

于 2017-02-26T05:16:22.117 に答える
-2

次のコマンドを使用して、pip で textblog をインストールしました。

sudo pip install textblob

そして、次のコマンドでコーパスをダウンロードしました:

python -m textblob.download_corpora

これは、textblob Web サイトの例では問題なく機能します。

コマンドで実行する例を次に示します。./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();
于 2015-06-10T17:29:52.037 に答える