我正在尝试使用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
会导致解析错误的任何想法?