With Python 3 being the future of Python while Python 2 continues to be in energetic need, it is good to get job designed for both biggest secretes of Python. This informative guide is supposed to guide you to work out how best to help both Python 2 3 concurrently.
If you are looking to port an extension component versus pure Python rule, kindly read Porting expansion Modules to Python 3 .
If you’d like to read one core Python creator’s accept precisely why Python 3 came into existence, look for Nick Coghlan’s Python 3 Q A or Brett canon’s precisely why Python 3 is present.
The brief ExplanationA¶
Incorporate Pylint to make positive that you do not regress on your Python 3 service ( python -m pip install pylint sexy mumbaian women )
Use caniusepython3 to discover which of the dependencies are blocking your own usage of Python 3 ( python -m pip install caniusepython3 )
When your dependencies are no longer blocking you, use continuous integration to ensure that you stay compatible with Python 2 3 (tox might help taste against several variations of Python; python -m pip install tox )
Consider utilizing recommended fixed means checking to be sure their sort use works in Python 2 3 (e.g. utilize mypy to test the typing under both Python 2 Python 3; python -m pip install mypy ).
Mention: Using python -m pip apply assurances your pip you invoke will be the one setup for any Python currently being used, whether it be a system-wide pip or one setup within an online environment .
A key point about supporting Python 2 3 concurrently is you can start these days! Even in the event their dependencies commonly encouraging Python 3 yet that does not mean you can’t modernize your own code today to aid Python 3. the majority of changes necessary to support Python 3 induce cleaner rule utilizing newer tactics even yet in Python 2 signal.
Another key point would be that modernizing their Python 2 rule to furthermore help Python 3 is essentially automated obtainable. You might need to make some API choices due to Python 3 clarifying text information versus digital data, the lower-level tasks are today typically accomplished for you and thus can about benefit from the automated changes instantly.
Keep those key points at heart although you read on concerning specifics of porting the signal to guide Python 2 3 simultaneously.
Fall service for Python 2.6 and olderA¶
While you will make Python 2.5 use Python 3, truly a lot easier should you decide just work with Python 2.7. If losing Python 2.5 is not an option then the six project assists you to help Python 2.5 3 at the same time ( python -m pip install six ). Carry out understand, however, that almost all the works placed in this HOWTO will never be accessible to you.
If you find yourself able to miss Python 2.5 and old, then the expected adjustment to your code should always feel like idiomatic Python rule. At the worst you will have to need a purpose in place of a technique sometimes or have to import a function in place of making use of an integral one, but otherwise the overall change must not think overseas to you.
However you should try to get merely supporting Python 2.7. Python 2.6 is no longer easily supported and thus isn’t getting bugfixes. This means you will have to operate around any dilemmas you come across with Python 2.6. There are additionally some apparatus pointed out within HOWTO which do not supporting Python 2.6 (e.g., Pylint), and this will much more commonplace as time goes on. It will simply feel simpler for you in the event that you best support the variations of Python you have to supporting.