0%

Requirements File Format

Requirements文件是包含需要使用pip install安装的项目列表文件。

Requirements文件的每一行都是一条要安装的内容,就像pip install的参数一样,支持以下形式:

1
2
3
4
5
[[--option]...]
<requirement specifier> [; markers] [[--option]...]
<archive url/path>
[-e] <local project path>
[-e] <vcs project url>

可以使用#来表示注释,行尾以\表示折行。

Options

Requirement Specifiers

requirement specifier由项目名称和可选的版本说明组成。如:

1
2
3
4
5
SomeProject
SomeProject == 1.3
SomeProject >=1.2,<2.0
SomeProject[foo, bar]
SomeProject~=1.4.2

从6.0开始,pip支持environment markers。如:

1
2
SomeProject ==5.4 ; python_version < '2.7'
SomeProject; sys_platform == 'win32'

从19.1开始,pip支持direct references,如:

1
2
3
4
pip @ file:///localbuilds/pip-1.3.1.zip
pip @ https://github.com/pypa/pip/archive/1.3.1.zip#sha1=da9234ee9982d4bbb3c72346a6de940a148ea686
pip @ git+https://github.com/pypa/pip.git@7921be1537eac1e97bc40179a57f0349c2aee67d
pip @ git+https://github.com/pypa/pip.git@1.3.1#7921be1537eac1e97bc40179a57f0349c2aee67d

从7.0版开始,pip支持通过requirements file控制为setup.py提供的命令行选项。

--global-option--install-option选项用于将选项传递给setup.py。例如:

1
2
3
FooProject >= 1.2 --global-option="--no-user-cfg" \
--install-option="--prefix='/usr/local'" \
--install-option="--no-compile"

相当于运行了:

1
python setup.py --no-user-cfg install --prefix='/usr/local' --no-compile

Archives

archive url/path.

Local Project Path

local project path.

Vcs Project Url

pip支持从GitMercurialSubversionBazaar安装,并使用URL前缀git+hg+svn+bzr+检测VCS的类型。

Git

1
2
3
4
[-e] git+http://git.example.com/MyProject#egg=MyProject
[-e] git+https://git.example.com/MyProject#egg=MyProject
[-e] git+ssh://git.example.com/MyProject#egg=MyProject
[-e] git+file:///home/user/projects/MyProject#egg=MyProject

Mercurial

1
2
3
4
[-e] hg+http://hg.myproject.org/MyProject#egg=MyProject
[-e] hg+https://hg.myproject.org/MyProject#egg=MyProject
[-e] hg+ssh://hg.myproject.org/MyProject#egg=MyProject
[-e] hg+file:///home/user/projects/MyProject#egg=MyProject

Subversion

1
2
3
[-e] svn+https://svn.example.com/MyProject#egg=MyProject
[-e] svn+ssh://svn.example.com/MyProject#egg=MyProject
[-e] svn+ssh://user@svn.example.com/MyProject#egg=MyProject

Bazaar

1
2
3
4
5
[-e] bzr+http://bzr.example.com/MyProject/trunk#egg=MyProject
[-e] bzr+sftp://user@example.com/MyProject/trunk#egg=MyProject
[-e] bzr+ssh://user@example.com/MyProject/trunk#egg=MyProject
[-e] bzr+ftp://user@example.com/MyProject/trunk#egg=MyProject
[-e] bzr+lp:MyProject#egg=MyProject