Why is django 2 available under python 2?

前端 未结 1 1898
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 20:32

According to Django 2.0 release notes Django 2.0 onwards will only support python 3, making the 1.11.X the last release series to support python 2.

See quote from the

相关标签:
1条回答
  • 2020-12-03 21:08

    Why is pip attempting to install Django2 with python2 instead of automatically picking the last compatible version? Isn't that part of pips capabilities?

    As Alasdair pointed out in the comments already, this is a known bug in Django: bug #28878.

    Is there a way to make a single requirements.txt that will install Django<2.0 when running from python2 and Django>=2.0 when running with python3?

    You can use the environment markers (see PEP 508):

    # requirements.txt
    django>=1.11,<2.0; python_version<"3.4"
    django>=2.0; python_version>="3.4"
    

    This will install one and skip another django dependency, depending on what python you are using:

    $ pip2.7 install -r requirements.txt 
    Ignoring django: markers 'python_version >= "3.4"' don't match your environment
    Collecting django<2.0 (from -r requirements.txt (line 1))
      Downloading Django-1.11.8-py2.py3-none-any.whl (6.9MB)
    ...
    
    $ pip3.6 install -r requirements.txt 
    Ignoring django: markers 'python_version < "3.4"' don't match your environment
    Collecting django>=2.0 (from -r requirements.txt (line 2))
      Using cached Django-2.0-py3-none-any.whl
    ...
    
    0 讨论(0)
提交回复
热议问题