Python 是否可以从install\u requires中获得setuptools extras\u require覆盖要求?

Python 是否可以从install\u requires中获得setuptools extras\u require覆盖要求?,python,pip,setuptools,Python,Pip,Setuptools,是否可以让setuptools的extras\u require覆盖install\u requires中设置的需求?我的猜测是否定的,因为extras\u require是一个 因此,由于它是“可选的”,因此install\u requires将始终优先。我想我会问一下以防万一 问这个问题的原因是下面的用例和下面的示例setup.py from setuptools import setup, find_packages setup( ... install_requires = [

是否可以让setuptools的
extras\u require
覆盖
install\u requires
中设置的需求?我的猜测是否定的,因为
extras\u require
是一个

因此,由于它是“可选的”,因此
install\u requires
将始终优先。我想我会问一下以防万一

问这个问题的原因是下面的用例和下面的示例
setup.py

from setuptools import setup, find_packages
setup(
  ...
  install_requires = [
    'numpy<=1.14.5,>=1.14.0',
    ...
  ],
  extras_require = {
    ...
    'tensorflow':[
       'tensorflow>=1.10.0',
       'numpy<=1.14.5,>=1.13.3',
       'setuptools<=39.1.0',
    ]
  },
  ...
)
from setuptools import setup, find_packages
setup(
  ...
  install_requires = [
    'scipy', # scipy requires numpy, and so will get the latest release from PyPI
    ...
  ],
  extras_require = {
    ...
    'tensorflow':[
       'tensorflow>=1.10.0',
       'numpy<=1.14.5,>=1.13.3',
       'setuptools<=39.1.0',
    ]
  },
  ...
)
然后对于需要TensorFlow的用户,他们只需要使用

pip install -e .[tensorflow]
但是,这当然不起作用,因为如果
install\u requires
只是
numpy>=1.14.0
,那么就安装了最新的PyPI版本的numpy(此时
1.15.1
),并且在安装时会收到警告

tensorflow 1.10.1 has requirement numpy<=1.14.5,>=1.13.3, but you'll have numpy 1.15.1 which is incompatible.
答案(经过一点思考后)是,结果是理想的是可能的,但不是通过覆盖
install\u requires
,而是在
install\u requires
中有一个需要所需库的需求(因此这是相当有难度的)。说明如何使用此
setup.py

from setuptools import setup, find_packages
setup(
  ...
  install_requires = [
    'numpy<=1.14.5,>=1.14.0',
    ...
  ],
  extras_require = {
    ...
    'tensorflow':[
       'tensorflow>=1.10.0',
       'numpy<=1.14.5,>=1.13.3',
       'setuptools<=39.1.0',
    ]
  },
  ...
)
from setuptools import setup, find_packages
setup(
  ...
  install_requires = [
    'scipy', # scipy requires numpy, and so will get the latest release from PyPI
    ...
  ],
  extras_require = {
    ...
    'tensorflow':[
       'tensorflow>=1.10.0',
       'numpy<=1.14.5,>=1.13.3',
       'setuptools<=39.1.0',
    ]
  },
  ...
)

from setuptools import setup, find_packages
setup(
  ...
  install_requires = [
    'scipy', # scipy requires numpy, and so will get the latest release from PyPI
    ...
  ],
  extras_require = {
    ...
    'tensorflow':[
       'tensorflow>=1.10.0',
       'numpy<=1.14.5,>=1.13.3',
       'setuptools<=39.1.0',
    ]
  },
  ...
)
$ pip install .
$ pip freeze | grep numpy
numpy==1.15.1
$ pip freeze | grep scipy
scipy==1.1.0
$ pip freeze | xargs pip uninstall -y
$ pip install .[tensorflow]
$ pip freeze | grep numpy
numpy==1.14.5
$ pip freeze | grep scipy
scipy==1.1.0