What is 'extra' in pypi dependency?

大憨熊 提交于 2019-12-19 21:41:28

问题


In requires_dist section of a package's json response from pypi, it is given:

requires_dist : [
    "bcrypt; extra == 'bcrypt'",
    "argon2-cffi (>=16.1.0); extra == 'argon2'"
]

can anyone make it clear the second statement of each dependency, extra == 'bcrypt' and extra == 'argon2'?


回答1:


Extras are dependencies you can install in addition to the regular dependencies, if you ask for them explicitly. See them as optional features.

You can install these with the name after the ==, with the name of the package. For example, if you install somepackage and want to add the bcrypt optional feature, use:

pip install somepackage[bcrypt]

or

pip install somepackage[argon2]

or, to include both optional extras, separate the names with commas:

pip install somepackage[bcrypt,argon2]

although using somepackage[...] multiple times also works as pip is smart enough to know that the main package is already installed.

pip (or whatever other package install tool) maps names listed in <packagename>[<extras_name>(,...)] to those entries in the requires_dict that use the <dependency_spec>; extra == '<extras_name>' format, adding on the dependency_specs to the list of things to install.

See Installing Setuptools "Extras" in the Installing Packages section of the Python Packaging User Guide.

It is up to the installed package itself to detect if all the dependencies for optional extra features are installed. A common pattern is to use try...except ImportError: guards to test for such extra dependencies being available.



来源:https://stackoverflow.com/questions/52474931/what-is-extra-in-pypi-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!