What do square brackets mean in pip install?

后端 未结 4 1236
甜味超标
甜味超标 2020-12-01 04:23

I see more and more commands like this:

$ pip install \"splinter[django]\"

What do these square brackets do?

4条回答
  •  悲哀的现实
    2020-12-01 04:25

    Brackets [optional] in PIP signify optional dependencies

    Just in case another developer comes along looking to implement this pattern in their own Python package deployment, here's further explanation of the brackets [] in pip.

    For Example: Apache Airflow

    To install airflow from pip we use this command:

    pip install 'apache-airflow'
    

    You can install optional components of airflow with:

    pip install 'apache-airflow[aws]'
    #      [optional] -----------^
    

    When we search pypi for apache-airflow note that the optional packages do not show up:

    pip search 'apache-airflow'
    
    apache-airflow (1.10.9)                            - Programmatically author, schedule and monitor data pipelines
    pylint-airflow (0.1.0a1)                           - A Pylint plugin to lint Apache Airflow code.
    swe-airflow-tools (0.0.3)                          - Tools for Apache Airflow Application
    airflow (0.6)                                      - Placeholder for the old Airflow package
    ...
    

    Implementation via setup.py

    You can see how this was accomplished in the setup.py script
    On the left in setup.py - extras_require is defined.
    On the right are the correlated installation commands for these optional sub-packages.

提交回复
热议问题