手头的答案是使用例如诗歌,如果可以的话,默认情况下并行下载/安装。但问题是关于点子的,所以:
如果你们中的一些人需要安装requirements.txt
具有hash
参数和 python 说明符(或只是散列)的依赖项,则不能正常使用pip install
,因为它不支持它。您唯一的选择是使用pip install -r
所以问题是如何从每个依赖项都定义了哈希和 python 说明符的需求文件中并行安装?这里是需求文件的外观:
swagger-ui-bundle==0.0.9; python_version >= "3.8" and python_version < "4.0" \
--hash=sha256:cea116ed81147c345001027325c1ddc9ca78c1ee7319935c3c75d3669279d575 \
--hash=sha256:b462aa1460261796ab78fd4663961a7f6f347ce01760f1303bbbdf630f11f516
typing-extensions==4.0.1; python_version >= "3.8" and python_version < "4.0" \
--hash=sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b \
--hash=sha256:4ca091dea149f945ec56afb48dae714f21e8692ef22a395223bcd328961b6a0e
unicon.plugins==21.12; python_version >= "3.8" and python_version < "4.0" \
--hash=sha256:07f21f36155ee0ae9040d810065f27b43526185df80d3cc4e3ede597da0a1c72
这是我带来的:
# create temp directory where we store split requirements
mkdir -p pip_install
# join lines that are separated with `\` and split each line into separate
# requirements file (one dependency == one file),
# and save files in previously created temp directory
sed ':x; /\\$/ { N; s/\\\n//; tx }' requirements.txt | split -l 1 - pip_install/x
# collect all file paths from temp directory and pipe them to xargs and pip
find pip_install -type f | xargs -t -L 1 -P$(nproc) /usr/bin/python3 -mpip install -r
# remove temp dir
rm -rf pip_install