How to pip install a package with min and max version range?

后端 未结 3 632
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 06:37

I\'m wondering if there\'s any way to tell pip, specifically in a requirements file, to install a package with both a minimum version (pip install package>=0.2

相关标签:
3条回答
  • 2020-12-02 07:13

    An elegant method would be to use the ~= compatible release operator according to PEP 440. In your case this would amount to:

    package~=0.5.0
    

    As an example, if the following versions exist, it would choose 0.5.9:

    • 0.5.0
    • 0.5.9
    • 0.6.0

    For clarification, each pair is equivalent:

    ~= 0.5.0
    >= 0.5.0, == 0.5.*
    
    ~= 0.5
    >= 0.5, == 0.*
    
    0 讨论(0)
  • 2020-12-02 07:21

    you can also use:

    pip install package==0.5.*
    

    which is more consistent and easy to read.

    0 讨论(0)
  • 2020-12-02 07:35

    You can do:

    $ pip install "package>=0.2,<0.3"
    

    And pip will look for the best match, assuming the version is at least 0.2, and less than 0.3.

    This also applies to pip requirements files. See the full details on version specifiers in PEP 440.

    0 讨论(0)
提交回复
热议问题