简体   繁体   中英

Python 2.7.X to 2.7.Y compatibility

I want to develop and test my project on the up-to-date version of Python 2.7 (say 2.7.18 ), but I want my project to be still fully usable on earlier versions of 2.7 (say 2.7.7 ). Setting up many variants of 2.7 locally or/and on CI for testing can be redundant.

So there are the following questions about compatibility of 2.7.X .

  1. Can there be any changes in syntax which make code not working?
  2. Can there be any changes in available standard imports , for example, can some imports from __future__ be unavailable in earlier versions?
  3. Since I have to distribute compiled Python files ( .pyc , compiled via py_compile module), I'm also wondering if there can be any changes in Python bytecode which block code execution in earlier versions.

I guess if all the answers are "no", I can develop and test my project only on a single 2.7 version without worries.

I've tried to search it but there is no success. Please share your experience and/or links.

UPD 1 : I should have clearly said from the beginning that it's not my desire to use 2.7 , it's a requirement from the environment.

At least Python 2.7.9 introduced massive changes to the 'ssl' module, so trying to use code using SSL for 2.7.18 on Python older than 2.7.9 will fail. So a clear "yes" to number 2.

In general compatbility for most projects works the other way round, use the oldest version you need to support and work upwards from old to new, not downwards from newer to older. I do not know of any software project that makes the guarantees in the other direction.

Note that Python 2.7 dropped out of support with 2.7.18, so unless you use a compatible version like PyPy ( https://www.pypy.org/ ) your freshly developed project will run on outdated Python versions from the start.

If you want to provide a shrink wrapped product, maybe have a look at the usual solution for this like pyinstaller ( https://www.pyinstaller.org/ ) or freeze ( https://wiki.python.org/moin/Freeze )

The #3 may work, if you study the list of bytecode opcodes which do not change that much over time ( https://github.com/python/cpython/commits/2.7/Include/opcode.h ) but no idea if the on-disk format changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM