无效的需求,尝试在Requirements.txt中使用--install-option时解析“'--instal'”处的错误

时间:2018-11-15 16:06:21

标签: python pip setuptools setup.py

我正在尝试使用setup.py和requirements.txt安装python模块。我使用pip install -U .文件所在的目录中的setup.py安装模块。

我的setup.py文件通过将需求存储在字符串列表中来解析requirements.txt文件:

def get_requirements():
    root_path = os.path.abspath(os.path.dirname(__file__))
    requirements_file_path = os.path.join(root_path, 'requirements.txt')

    # example: `numpy >= 1.13`
    with open(requirements_file_path) as file:
        requirements = [requirement.strip() for requirement in file.readlines()]
        requirements = filter(lambda requirement: len(requirement), requirements)
        requirements = filter(lambda requirement: not requirement.startswith('-'), requirements)
        requirements = list(requirements)

    return requirements

requirements = get_requirements()
config = {'name': name, 
          'install_requires': requirements
}
setuptools.setup(**config)

我的需求文件如下:

numpy >= 1.13
pyyaml >= 3.12
matplotlib
opencv-python >= 3.2
setuptools
cython
mock
scipy
six
future
protobuf
yacs
ninja
colour
torchvision_nightly
torch_nightly --install-option="--find-links https://download.pytorch.org/whl/nightly/cu92/torch_nightly.html"

但是,当我尝试使用pip install -U .安装模块时,出现以下解析错误:

Processing /home/my-module
    Complete output from command python setup.py egg_info:
    error in my_module setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'--instal'"

----------------------------------------

/ tmp / pip-req-build-rf9439sf /

中的命令“ python setup.py egg_info”失败,错误代码为1

关于为什么传递--install-option会导致解析错误的任何想法?

1 个答案:

答案 0 :(得分:1)

setuptools中的

Declaration of dependencies的语法与pip的语法不同。您必须自动或手动将一个转换为另一个。