通过PIP安装平台特定依赖项

2 投票
2 回答
1192 浏览
提问于 2025-04-20 03:53

我在测试中使用LDTP,它有两个不同的平台包:

  • 在Mac OS上使用PyAtom;
  • 在Linux上使用LDTP。

这两个包都是针对特定平台的二进制文件,不能在其他操作系统上安装。我的问题是,如何在我的requirements.txt文件中设置依赖于平台的包?

理想情况下,它应该像这样:

mac:
  -e git+https://github.com/pyatom/pyatom.git@1ca0c6a0343000286a328268899d1aab376d8e82#egg=atomac-master
linux:
  ldtp==3.5.0
holmium.core==0.7.6
pytest==2.5.2
selenium==2.42.1

2 个回答

-1

也许你可以为每个平台的需求创建一个文件:

requirements-windows.txt
requirements-linux.txt
requirements-mac.txt

然后你可以运行,比如说:

pip install -r requirements-mac.txt

如果你愿意的话...

0

根据@wim的评论中的链接(https://www.python.org/dev/peps/pep-0508/#environment-markers),我们发现sys_platform可以解决这个问题。

-e git+https://github.com/...#egg=atomac-master;sys_platform=="darwin"
ldtp==3.5.0;sys_platform!="darwin"
holmium.core==0.7.6
pytest==2.5.2
selenium==2.42.1

不同的Python版本,比如CPython和Jython等,也有类似的选项。

(出于我现在记不清的历史原因,“darwin”这个名字通常用来指代MacOS。)

撰写回答