我正在尝试让 pip 根据用户的平台从不同的来源安装 numpy。我试图通过使用“platform_system”环境标记来实现这一 pip 。
# 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 上什至没有正确的文件路径 - 即使它受到“platform_system”的保护。
Requirement '/python35/wheels_repo/numpy-1.12.0.whl' looks like a filename, but the file does not exist
然后安装停止。
有没有办法让 pip 不寻找这个文件,或者至少在找不到文件时恢复安装?
最佳答案
我相信 pip 会一直检查文件是否存在。并且此检查在检查安装要求(即环境标记是否匹配)之前完成。
但是,如果找不到文件,您可以让 pip 继续安装。 罢工>
只需更改您的要求:
/python35/wheels_repo/numpy-1.12.0.whl;platform_system == "Linux"
到:
--find-links "file:///python35/wheels_repo/" numpy-1.12.0.whl;platform_system == "Linux"
使用 --find-links pip 将进入另一个控制流,稍后会评估 URI,并且仅在它无效或未找到资源时才会打印警告.罢工>
编辑:
我刚刚意识到 --find-links 不适用于 requirements.txt 中的单个需求。
由于您不是简单地为每个平台安装不同的包,而是为每个平台安装来自不同来源的不同包,我建议将平台特定要求分成不同的文件(即:requirements_Windows.txt 和 requirements_Linux.txt ) 并在每个平台上以不同方式运行“pip install -r”。
在 Windows 上,您可以使用即 pip2pi 构建本地包存储库。然后运行:
pip install --extra-index-url file://[path-to-your-local-package-repository]/simple -r requirements_Windows.txt
关于python - 使用 pip 有条件地安装 wheel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44729216/