WSL:ImportError:无法导入名称“textblob”

2022-01-19 01:25:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在WSL的Python3上安装了NLTK和TextBlob。无论我做什么,我总是得到同样的错误。实际上,尝试安装表明所有软件包都已安装

$ sudo pip3 install -U textblob
The directory '/home/jlchulilla/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/jlchulilla/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: textblob in /usr/local/lib/python3.6/dist-packages
Requirement already up-to-date: nltk>=3.1 in /usr/local/lib/python3.6/dist-packages (from textblob)
Requirement already up-to-date: six in /usr/local/lib/python3.6/dist-packages (from nltk>=3.1->textblob)

但是,当我尝试更新语料库或使用from textblob import TextBlob时,以下是错误消息:

$ python3 -m textblob.download_corpora
Traceback (most recent call last):
  File "/usr/lib/python3.6/subprocess.py", line 140, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
  File "/usr/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/mnt/c/Users/jlchu/Dropbox/oando/COVID-19/Supermercados online y covid_csv/prácticas NLTK/tokenize.py", line 1, in <module>
    from textblob import textblob
ImportError: cannot import name 'textblob'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/usr/local/lib/python3.6/dist-packages/textblob/__init__.py", line 2, in <module>
    from .blob import TextBlob, Word, Sentence, Blobber, WordList
  File "/usr/local/lib/python3.6/dist-packages/textblob/blob.py", line 28, in <module>
    import nltk
  File "/usr/local/lib/python3.6/dist-packages/nltk/__init__.py", line 99, in <module>
    from nltk.internals import config_java
  File "/usr/local/lib/python3.6/dist-packages/nltk/internals.py", line 11, in <module>
    import subprocess
  File "/usr/lib/python3.6/subprocess.py", line 142, in <module>
    import dummy_threading as threading
  File "/usr/lib/python3.6/dummy_threading.py", line 45, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
  File "/usr/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/mnt/c/Users/jlchu/Dropbox/oando/COVID-19/Supermercados online y covid_csv/prácticas NLTK/tokenize.py", line 1, in <module>     
    from textblob import textblob
ImportError: cannot import name 'textblob'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3.6/subprocess.py", line 140, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
ImportError: cannot import name 'format_exc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 62, in apport_excepthook
    import re, traceback
  File "/usr/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/mnt/c/Users/jlchu/Dropbox/oando/COVID-19/Supermercados online y covid_csv/prácticas NLTK/tokenize.py", line 1, in <module>     
    from textblob import textblob
  File "/usr/local/lib/python3.6/dist-packages/textblob/__init__.py", line 2, in <module>
    from .blob import TextBlob, Word, Sentence, Blobber, WordList
  File "/usr/local/lib/python3.6/dist-packages/textblob/blob.py", line 28, in <module>
    import nltk
  File "/usr/local/lib/python3.6/dist-packages/nltk/__init__.py", line 99, in <module>
    from nltk.internals import config_java
  File "/usr/local/lib/python3.6/dist-packages/nltk/internals.py", line 11, in <module>
    import subprocess
  File "/usr/lib/python3.6/subprocess.py", line 142, in <module>
    import dummy_threading as threading
  File "/usr/lib/python3.6/dummy_threading.py", line 45, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
ImportError: cannot import name 'format_exc'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python3.6/subprocess.py", line 140, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
  File "/usr/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/mnt/c/Users/jlchu/Dropbox/oando/COVID-19/Supermercados online y covid_csv/prácticas NLTK/tokenize.py", line 1, in <module>     
    from textblob import textblob
ImportError: cannot import name 'textblob'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/usr/local/lib/python3.6/dist-packages/textblob/__init__.py", line 2, in <module>
    from .blob import TextBlob, Word, Sentence, Blobber, WordList
  File "/usr/local/lib/python3.6/dist-packages/textblob/blob.py", line 28, in <module>
    import nltk
  File "/usr/local/lib/python3.6/dist-packages/nltk/__init__.py", line 99, in <module>
    from nltk.internals import config_java
  File "/usr/local/lib/python3.6/dist-packages/nltk/internals.py", line 11, in <module>
    import subprocess
  File "/usr/lib/python3.6/subprocess.py", line 142, in <module>
    import dummy_threading as threading
  File "/usr/lib/python3.6/dummy_threading.py", line 45, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
  File "/usr/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/mnt/c/Users/jlchu/Dropbox/oando/COVID-19/Supermercados online y covid_csv/prácticas NLTK/tokenize.py", line 1, in <module>     
    from textblob import textblob
ImportError: cannot import name 'textblob'

我不明白问题出在哪里。任何帮助都将不胜感激

编辑:当我尝试导入NLTK库的任何其他模块时,同样的错误也会发生。这就像之前调用“tokenize”会阻止模块或其他东西一样

$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from nltk.stem.porter import PorterStemmer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/nltk/__init__.py", line 99, in <module>
    from nltk.internals import config_java
  File "/usr/local/lib/python3.6/dist-packages/nltk/internals.py", line 11, in <module>
    import subprocess
  File "/usr/lib/python3.6/subprocess.py", line 140, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
  File "/usr/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/mnt/c/Users/jlchu/Dropbox/oando/COVID-19/Supermercados online y covid_csv/prácticas NLTK/tokenize.py", line 1, in <module>
    from textblob import TextBlob
  File "/usr/local/lib/python3.6/dist-packages/textblob/__init__.py", line 2, in <module>
    from .blob import TextBlob, Word, Sentence, Blobber, WordList
  File "/usr/local/lib/python3.6/dist-packages/textblob/blob.py", line 35, in <module>
    from textblob.base import (BaseNPExtractor, BaseTagger, BaseTokenizer,
  File "/usr/local/lib/python3.6/dist-packages/textblob/base.py", line 44, in <module>
    class BaseTokenizer(with_metaclass(ABCMeta), nltk.tokenize.api.TokenizerI):
AttributeError: module 'nltk' has no attribute 'tokenize'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3.6/subprocess.py", line 140, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
ImportError: cannot import name 'format_exc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 62, in apport_excepthook
    import re, traceback
  File "/usr/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/mnt/c/Users/jlchu/Dropbox/oando/COVID-19/Supermercados online y covid_csv/prácticas NLTK/tokenize.py", line 1, in <module>     
    from textblob import TextBlob
  File "/usr/local/lib/python3.6/dist-packages/textblob/__init__.py", line 2, in <module>
    from .blob import TextBlob, Word, Sentence, Blobber, WordList
  File "/usr/local/lib/python3.6/dist-packages/textblob/blob.py", line 28, in <module>
    import nltk
  File "/usr/local/lib/python3.6/dist-packages/nltk/__init__.py", line 99, in <module>
    from nltk.internals import config_java
  File "/usr/local/lib/python3.6/dist-packages/nltk/internals.py", line 11, in <module>
    import subprocess
  File "/usr/lib/python3.6/subprocess.py", line 142, in <module>
    import dummy_threading as threading
  File "/usr/lib/python3.6/dummy_threading.py", line 45, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
ImportError: cannot import name 'format_exc'

Original exception was:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/nltk/__init__.py", line 99, in <module>
    from nltk.internals import config_java
  File "/usr/local/lib/python3.6/dist-packages/nltk/internals.py", line 11, in <module>
    import subprocess
  File "/usr/lib/python3.6/subprocess.py", line 140, in <module>
    import threading
  File "/usr/lib/python3.6/threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
  File "/usr/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/mnt/c/Users/jlchu/Dropbox/oando/COVID-19/Supermercados online y covid_csv/prácticas NLTK/tokenize.py", line 1, in <module>     
    from textblob import TextBlob
  File "/usr/local/lib/python3.6/dist-packages/textblob/__init__.py", line 2, in <module>
    from .blob import TextBlob, Word, Sentence, Blobber, WordList
  File "/usr/local/lib/python3.6/dist-packages/textblob/blob.py", line 35, in <module>
    from textblob.base import (BaseNPExtractor, BaseTagger, BaseTokenizer,
  File "/usr/local/lib/python3.6/dist-packages/textblob/base.py", line 44, in <module>
    class BaseTokenizer(with_metaclass(ABCMeta), nltk.tokenize.api.TokenizerI):
AttributeError: module 'nltk' has no attribute 'tokenize'