9

I have a requirements.txt as follows

boxsdk
boxsdk[jwt]

If I run pip install -r requirements.txt, then only boxsdk gets installed, and not boxsdk[jwt]

# cat requirements.txt 
boxsdk
boxsdk[jwt]
# pip -q install -r requirements.txt 
# python -c "import boxsdk.auth.jwt_auth"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/boxsdk/auth/jwt_auth.py", line 10, in <module>
    from cryptography.hazmat.backends import default_backend
ModuleNotFoundError: No module named 'cryptography'

But if I remove the first line so that only boxsdk[jwt] is listed in requirements.txt, it gets installed properly

# cat requirements.txt 
boxsdk[jwt]
# pip -q install -r requirements.txt 
# python -c "import boxsdk.auth.jwt_auth"
#

Full pip output can be seen here: https://gist.github.com/davidkazuhiro/989328734e128628dd53ccab741f3e45

Why is boxsdk[jwt] getting skipped in the former case?

David
  • 493
  • 7
  • 15

1 Answers1

11

Your requirements.txt is equivalent to the following command

pip install boxsdk boxsdk[jwt]

so my answer will be based on the above command.

According to What do square brackets mean in pip install?, boxsdk[jwt] specifies a variant of the boxsdk package.

Because you specified boxsdk in the first place, when going over boxsdk[jwt], pip notices that boxsdk has already been specified in the command line (or one same requirements.txt), and silently ignores duplicated package specification.

On the other hand, this command successfully installed everything:

pip install boxsdk[jwt] boxsdk

So, you should put the one with jwt before the other in your requirements.txt:

boxsdk[jwt]
boxsdk

This way, pip will ignore the latter and install as desired.

BUT the correct way to do this is to just throw away the other, making boxsdk[jwt] the only thing in your requirements.txt.

iBug
  • 35,554
  • 7
  • 89
  • 134
  • Thanks @iBug. Do you know of any documentation which specifies the behavior of "silently ignores duplicated package specification"? – David Feb 04 '19 at 01:04
  • @David Maybe [this GitHub issue](https://github.com/pypa/pip/issues/993)? – iBug Feb 04 '19 at 01:12
  • Ah so that's where the behaviour came in. It's definitely not documented though. https://pip.pypa.io/en/stable/reference/pip_install/#pip-install I've submitted an issue asking for improvement in their docs and output https://github.com/pypa/pip/issues/6239 Thanks! – David Feb 05 '19 at 00:34