Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does .[dev] mean in pip install -e .[dev] [duplicate]

I see more and more commands like this:

$ pip install "splinter[django]"

What do these square brackets do?

like image 706
Babken Vardanyan Avatar asked Oct 16 '17 16:10

Babken Vardanyan


People also ask

What is pip install Dev?

The pip install command installs by default the newest stable version of a python package (stable versions as specified by PEP426) The flag --pre for the pip install command tells pip also consider release candidates and develompent versions of python packages.

What is Python Dev?

It is a popular development package that contains the header files developers require to build Python extensions. Python-dev comprises the header documents for fabricating Python augmentations.

Why do I need Python Dev?

As a Python developer, you can do everything from web or game development to quantitative analysis, to creating new programming languages. Python is a programming language used for a variety of programming tasks, including artificial intelligence (AI), machine learning, data analytics, and data visualization.

How do I clear my pip cache?

If you want to force pip to clear out its download cache and use the specific version you can do by using --no-cache-dir command. If you are using an older version of pip than upgrade it with pip install -U pip. This will help you clear pip cache.


3 Answers

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.

like image 53
7 revs, 2 users 95% Avatar answered Oct 06 '22 00:10

7 revs, 2 users 95%


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.

setup.py vs install

like image 45
Ben DeMott Avatar answered Oct 06 '22 00:10

Ben DeMott


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” ...

like image 23
Paul Avatar answered Oct 06 '22 00:10

Paul