Python 使用pip有条件地安装控制盘文件

Python 使用pip有条件地安装控制盘文件,python,pip,Python,Pip,我正试图让pip根据用户的平台从不同的来源安装numpy。我试图通过使用“平台系统”环境标记来实现这一点 # requirements.txt # installing from a local wheel file /python35/wheels_repo/numpy-1.12.0.whl;platform_system == "Linux" # installing from PyPi numpy==1.12.0;platform_system == "Windows" 当我在Linu

我正试图让pip根据用户的平台从不同的来源安装numpy。我试图通过使用“平台系统”环境标记来实现这一点

# requirements.txt

# installing from a local wheel file
/python35/wheels_repo/numpy-1.12.0.whl;platform_system == "Linux"
# installing from PyPi
numpy==1.12.0;platform_system == "Windows"
当我在Linux上时,它工作正常,但当我在Windows上时,pip会搜索文件——在Windows上甚至没有正确的文件路径——即使它受到“平台\系统”的保护

然后安装停止


有没有办法让pip不查找此文件,或者在找不到文件时至少恢复安装?

我相信pip会一直检查文件是否存在。此检查在检查安装要求之前完成(即,如果环境标记匹配)

但是,如果找不到文件,您可以让pip继续安装

只需将您的要求从:

/python35/wheels_repo/numpy-1.12.0.whl;platform_system == "Linux"
致:

使用--find links,pip随后将进入另一个控制流,在该控制流中,URI将在稍后进行评估,并且只有在URI无效或未找到资源时才会导致打印警告

编辑:

我刚刚意识到--在requirements.txt中查找链接不能处理单个需求

由于您不只是为每个平台安装不同的软件包,而是为每个平台安装来自不同来源的不同软件包,因此我建议将特定于平台的需求分成不同的文件(即:requirements_Windows.txt和requirements_Linux.txt)并运行“pip install-r”在每个平台上都不同

在Windows上,您可以使用构建的本地包存储库,即,然后运行:

pip install --extra-index-url file://[path-to-your-local-package-repository]/simple -r requirements_Windows.txt
--find-links "file:///python35/wheels_repo/" numpy-1.12.0.whl;platform_system == "Linux"
pip install --extra-index-url file://[path-to-your-local-package-repository]/simple -r requirements_Windows.txt