我应该如何在我的在谷歌云实例上运行的jupyter笔记本上安装spacy的英文版本?

问题描述 投票:0回答:2

我正在尝试在 jyputer 笔记本(python 3)中使用 spaCy 的英文模型,它在谷歌云实例上运行。我已经安装了spaCy,但我的问题是我无法安装/导入它的英文模型。

我已经尝试过以下代码:

!pip3 install en_core_web_sm
!python -m spacy download en

和许多其他代码,但没有一个有效,每次我都会遇到不同的错误。当我在本地计算机上工作时,我使用 spacy 无忧无虑,但我不知道如何在云上运行的 jyputer 笔记本上安装英文模型。有什么建议么? 谢谢!

仅供参考:尝试时:

!pip3 install en_core_web_sm
, 我收到以下错误:

Collecting spacy-model-en_core_web_sm
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python3/dist-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python3/dist-packages/pip/index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 795, in get_page
    resp.raise_for_status()
  File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/models.py", line 893, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/spacy-model-en-core-web-sm/
python-3.x google-cloud-platform jupyter-notebook spacy
2个回答
9
投票

感谢@Dustin Ingram,我找到了答案。我应该输入:

!python3 -m spacy download en_core_web_sm

如果您使用 python 2,请在上面的命令中从 python 末尾删除“3”!

您可以通过以下方式在 Python 中运行它,就像在 Jupyter Notebook 中一样:

import spacy
spacy.cli.download('en_core_web_sm')

4
投票

有一个更好的方法,你不需要担心使用错误的python

import spacy
spacy.cli.download('en_core_web_sm')
© www.soinside.com 2019 - 2024. All rights reserved.