Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pip skip bracket package in requirements.txt?

Tags:

python

pip

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?

like image 572
David Avatar asked Feb 03 '19 06:02

David


1 Answers

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.

like image 123
iBug Avatar answered Oct 19 '22 22:10

iBug