setup.py 中的 spaCy 和 spaCy 模型 [英] spaCy and spaCy models in setup.py

查看:42
本文介绍了setup.py 中的 spaCy 和 spaCy 模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我的 setup.py 中有 spaCy 作为依赖项,但我还想添加一个默认模型.

In my project I have spaCy as a dependency in my setup.py, but I want to add also a default model.

到目前为止我的尝试是:

My attempt so far has been:

install_requires=['spacy', 'en_core_web_sm'],
dependency_links=['https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz#egg=en_core_web_sm'],

在我的 setup.py 中,但是我的包的常规 pip installpip install --process-dependency-links返回:

inside my setup.py, but both a regular pip install of my package and a pip install --process-dependency-links return:

pip._internal.exceptions.DistributionNotFound: No matching distribution found for en_core_web_sm (from mypackage==0.1)

我发现这个 来自 AllenAI 的 github 问题 有同样的问题,但没有解决方案.

I found this github issue from AllenAI with the same problem and no solution.

请注意,如果我直接pip install模型的url,它工作正常,但是当我的包使用pip install.

Note that if I pip install the url of the model directly, it works fine, but I want to install it as a dependency when my package is install with pip install.

推荐答案

您可以使用 pip 最近对 PEP 508 URL 要求的支持:

You can use pip's recent support for PEP 508 URL requirements:

install_requires=[
    'spacy',
    'en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz',
],

请注意,这要求您使用最新版本的 setuptools 和 wheel(至少 v0.32.0 for wheel;不确定 setuptools)构建您的项目,并且您的用户只能在以下情况下安装您的项目他们至少使用 18.1 版的 pip.

Note that this requires you to build your project with up-to-date versions of setuptools and wheel (at least v0.32.0 for wheel; not sure about setuptools), and your users will only be able to install your project if they're using at least version 18.1 of pip.

不过,更重要的是,如果您打算在 PyPI 上分发您的包,这不是一个可行的解决方案;引用 pip 的发行说明:

More importantly, though, this is not a viable solution if you intend to distribute your package on PyPI; quoting pip's release notes:

作为一项安全措施,如果从 PyPI 安装软件包时,pip 将引发异常,如果这些软件包依赖于未托管在 PyPI 上的软件包.将来,PyPI 将阻止直接上传具有此类外部 URL 依赖项的包.

As a security measure, pip will raise an exception when installing packages from PyPI if those packages depend on packages not also hosted on PyPI. In the future, PyPI will block uploading packages with such external URL dependencies directly.

这篇关于setup.py 中的 spaCy 和 spaCy 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆