在尝试使用
nltk.stem.WordNetLemmatizer()
时,我收到以下错误。
LookupError:
**********************************************************************
Resource wordnet not found.
Please use the NLTK Downloader to obtain the resource:
>>> import nltk
>>> nltk.download('wordnet')
For more information see: https://www.nltk.org/data.html
当我去运行这个时
import nltk
nltk.download('wordnet')
我收到此解析错误
Traceback (most recent call last):
File ~\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:3460 in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
Cell In[32], line 2
nltk.download('wordnet')
File ~\Anaconda3\lib\site-packages\nltk\downloader.py:777 in download
for msg in self.incr_download(info_or_id, download_dir, force):
File ~\Anaconda3\lib\site-packages\nltk\downloader.py:629 in incr_download
info = self._info_or_id(info_or_id)
File ~\Anaconda3\lib\site-packages\nltk\downloader.py:603 in _info_or_id
return self.info(info_or_id)
File ~\Anaconda3\lib\site-packages\nltk\downloader.py:1009 in info
self._update_index()
File ~\Anaconda3\lib\site-packages\nltk\downloader.py:952 in _update_index
ElementTree.parse(urlopen(self._url)).getroot()
File ~\Anaconda3\lib\xml\etree\ElementTree.py:1222 in parse
tree.parse(source, parser)
File ~\Anaconda3\lib\xml\etree\ElementTree.py:580 in parse
self._root = parser._parse_whole(source)
File <string>
ParseError: mismatched tag: line 33, column 2
我最初在 Jupyter Notebook 中运行代码,重新启动内核并重试。我还尝试在 Python 解释器中运行它。每次都给我同样的错误。
nltk版本是3.7
我的问题可能还有其他解决方案,我最终解决这个问题的方法是从 https://www.nltk.org/nltk_data/ 手动下载 wordnet 并将文件保存在文档告诉您的位置(C : ltk_数据