1

The Python docs specifically mention that you should use double quotes with pip when installing specific package versions:

When using comparator operators such as >, < or some other special character which get interpreted by shell, the package name and the version should be enclosed within double quotes:

python -m pip install SomePackage==1.0.4    # specific version
python -m pip install "SomePackage>=1.0.4"  # minimum version

This is unexpected for me since most Unix shells expand variables within double quotes but not single quotes, and I would expect us to want the string to be passed literally to pip without any possible shell expansion taking place.

I mostly see pip used with single quotes "in the wild" and the second comment on this answer makes me think that this is a Windows compatibility issue. Is this correct or is there any advantage of using double quotes with pip in Unix shells such as Bash and Zsh?

joelostblom
  • 43,590
  • 17
  • 150
  • 159
  • "*…makes me think that this is a Windows compatibility issue…*" Shouldn't this part of the question be directed to the `pip` authors? We can only guess, not know. – phd Jun 30 '22 at 21:45
  • @phd Yup, it is possible this is a questions that can only be answered by the pip dev team, but it is also possible that there is a more general answer which is why I asked on SO first (e.g. maybe double quotes are always preferred when on windows because of something related to the default CMD shell). – joelostblom Jun 30 '22 at 23:49

1 Answers1

2

is there any advantage of using double quotes with pip in Unix shells such as Bash and Zsh?

Supposing that the point is strictly to ensure that the (other) characters of an argument are all treated as ordinary characters, no, double quotes are strictly worse than single quotes for that usage in Bourne-family shells such as Bash and Zsh. In practice, however, I don't think the difference would actually be relevant to any package specification that pip would accept.

Note well that at least on Unixen such as Linux and Mac, pip factors in only from the perspective of what command-line arguments one expects to want to provide. The executed command (i.e. pip) sees only the results of command-line processing, including quote removal. It has no idea what kind of quoting, if any, was used.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Thanks! Especially this section was helpful which is something I was wondering " In practice, however, I don't think the difference would actually be relevant to any package specification that pip would accept." – joelostblom Jun 30 '22 at 23:59