With Python 3 are the ongoing future of Python while Python 2 is still in productive incorporate, it is good kissbrides.com/hot-kazakhstan-women/ to have your job readily available for both major secretes of Python. This guide is supposed to help you figure out how best to support both Python 2 3 concurrently.
If you are looking to port an expansion component instead of pure Python code, kindly see Porting Extension Modules to Python 3 .
If you wish to learn one center Python designer’s deal with exactly why Python 3 came into existence, you can read Nick Coghlan’s Python 3 Q A or Brett Cannon’s exactly why Python 3 is out there.
The Short ExplanationA¶
Incorporate Pylint to make certain that you don’t regress on your Python 3 support ( python -m pip install pylint )
Need caniusepython3 to learn which of your dependencies become stopping your own use of Python 3 ( python -m pip install caniusepython3 )
Once your dependencies are no much longer stopping your, use constant integration to ensure that you remain compatible with Python 2 3 (tox might help try against multiple variations of Python; python -m pip install tox )
Contemplate using optional fixed means examining to ensure your own sort consumption operates both in Python 2 3 (e.g. need mypy to test your typing under both Python 2 Python 3; python -m pip install mypy ).
Note: Using python -m pip apply guarantees your pip your invoke will be the one installed the Python at this time used, whether it’s a system-wide pip or one set up within an online environment .
DetailsA¶
A key point about promoting Python 2 3 concurrently is that you can starting today! Even though their dependencies aren’t promote Python 3 yet that doesn’t imply it’s not possible to modernize the laws today to support Python 3. Many modifications required to support Python 3 result in cleaner code utilizing newer techniques inside Python 2 rule.
Another key point would be that modernizing your own Python 2 code to in addition supporting Python 3 is largely automated individually. Even if you need to make some API choices courtesy Python 3 clarifying text data versus binary facts, the lower-level efforts are today typically done for you and therefore can at least enjoy the robotic adjustment right away.
Keep those key points at heart whilst you keep reading regarding specifics of porting your own signal to compliment Python 2 3 simultaneously.
Fall assistance for Python 2.6 and olderA¶
Although you make Python 2.5 deal with Python 3, it is a lot easier if you only have to work with Python 2.7. If dropping Python 2.5 isn’t an option then six project assists you to help Python 2.5 3 simultaneously ( python -m pip install six ). Do understand, however, that most the work listed in this HOWTO are not accessible to you.
If you find yourself able to skip Python 2.5 and old, then your required changes your code should continue steadily to feel and look like idiomatic Python signal. At worst you will have to use a features as opposed to a way in some instances or need transfer a function versus making use of an integral one, but if not the entire transformation shouldn’t believe overseas for your requirements.
However you should shoot for only encouraging Python 2.7. Python 2.6 is no longer easily recognized and so is not receiving bugfixes. This implies you’re going to have to work around any problems you find with Python 2.6. Additionally, there are some hardware pointed out contained in this HOWTO which do not support Python 2.6 (e.g., Pylint), which will be prevalent in the future. It’s going to merely be simpler for you in the event that you only support the versions of Python that you have to help.