如何使用脚本在 python 中安装特定版本的 module/library

How to install a specific version of module/library in python using a script

我已经编写了一个脚本,使用 Python 的 subprocess 模块安装所需的模块。

比如我要安装altgraphs,我会写如下代码:

subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'altgraph'])

但这将安装最新版本的“altgraph”模块。但是我希望只安装特定版本的模块。假设我要安装0.17.1版本,那么代码应该是什么?

像这样指定包版本:

subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'altgraph==0.17.1'])