How to specify bracket dependencies in setup.py?

2019-09-21 12:58发布

Related to this question: What do square brackets mean in pip install?

I have a setup.py file that needs to install azure[common] package. However, if I try:

setup(
    ...
    install_requires=['azure[common]'],
    ...
)

This results in an error:

pkg_resources.UnknownExtra: azure 4.0.0 has no such extra feature 'common'

But, if I do:

pip install 'azure[common]', then it works.

There were a lot of bugs and unexpected behavior involved in the experiment above, so the question doens't really make sense anymore.

  1. There's a bug in pip which causes random stuff to be installed if "extra" package isn't found. So, pip install 'azure[common]' shouldn't have worked at all. It's an error that led me to believe there was such a package.
  2. There's an inconsistency between how setuptools and pip install packages from wheels. setuptools installs (or seems to) only install one package from a wheel, while pip will install everything, and if there are more than one package, then it will install more. So, pip was installing azure.common by mistake, but there is no way to intentionally install just that package. At the minimum, you will also get azure.profiles plus a fake package azure_common, which doesn't really contain anything.

Given all this new info, I reformulated the question here: How to make setuptools install a wheel containing multiple packages?

1条回答
The star\"
2楼-- · 2019-09-21 13:35

Azure does not provide the common extra dependency. pip install azure[common] shows the warning about it.

查看更多
登录 后发表回答