What do square brackets mean in pip install?

2020-02-02 10:04发布

I see more and more commands like this:

$ pip install "splinter[django]"

What do these square brackets do?

3条回答
混吃等死
2楼-- · 2020-02-02 10:53

This is exactly the list from the setup.py file for the project in question:

"django": ["Django>=1.7.11;python_version<'3.0'", "Django>=2.0.6;python_version>'3.3'", "lxml>=2.3.6", "cssselect", "six"],
查看更多
相关推荐>>
3楼-- · 2020-02-02 11:00

Pretty sure these are setuptools extras:

https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies

Sometimes a project has “recommended” dependencies, that are not required for all uses of the project. For example, a project might offer optional PDF output if ReportLab is installed, and reStructuredText support if docutils is installed. These optional features are called “extras” ...

查看更多
时光不老,我们不散
4楼-- · 2020-02-02 11:03

The syntax that you are using is:

pip install "project[extra]"

In your case, you are installing the splinter package which has the added support for django. The square brackets ([]) are not specific syntax, just convention. Really, you are installing the package named: "splinter[django]".

An explanation from @chetner:

The command pip install splinter django would install two packages named splinter and django. splinter[django], on the other hand, installs a variant of the splinter package which contains support for django. Note that it has nothing to do with the django package itself, but is just a string defined by the splinter package for a particular feature set that gets enabled.

查看更多
登录 后发表回答