Backward compatibility of Python versions

I need to use Python version 2.7 in a Python virtual environment on my Raspberry Pi 4 Model B computer (which already has Python version 2.7.16 on it plus Python version 3.7.3). Is Python version 2.7.16 backward compatible with Python version 2.7? In other words, can I go ahead and use Python version 2.7.16 in place of Python 2.7 in my Python virtual environment, or should I go ahead and download Python version 2.7 to my Raspberry Pi computer? Any advice would be greatly appreciated. Thanks.

The question that springs to my mind is why the ‘need’ to use V2.7

The major change came with V3 and as such I don’t see that you’d have any real issues (such as the syntax, which is the headache when converting V2.7 scripts to V3.x).

Other, more experienced peeps, here may have a better idea.

I think you are confused about what ‘Python version 2.7’ is. Python 2.7.16 belongs to Python 2.7. Python 2.7 is not one single release but a series of releases. As with many pieces of software, there are three components to the version number: major.minor.micro. A specific Python version has the three numbers, for instance 2.7.16. If you are given only the two first numbers, it means “any version having these two first numbers”, so you can use 2.7.5, 2.7.1, … whichever you want. To take an analogy, your question is a bit like “is Python from August 2010 backwards compatible with Python from year 2010”? Well, Python from August 2010 is from 2010.

The reason why the micro (third number) does not matter very much is that, traditionally, the difference between micro releases (major.minor.micro and major.minor.(micro+1)) is only bug fixes, never new features or backwards incompatible changes. If you have code that works under Python 2.7.12, it will continue to work (with extremely rare exceptions perhaps) under Python 2.7.16. Cf. Semantic Versioning. Therefore, usually, people speak in terms of major.minor. In the specific case that bug you care about has been fixed, you want to look at the minor numbers. Also, OSes have evolved a lot in 10 years, so Python 2.7.0 is likely no longer buildable under current systems – bug fixes include build fixes too. Generally speaking, you want to prefer using the latest micro release in a minor release series. In this case, the latest version is 2.7.18 (Python Release Python 2.7.18 | Python.org), so try that one.

On the other hand, be aware that Python 2 is no longer supported. It is strongly recommended to switch over Python 3.

2 Likes

Python 2.7.16 is the 16th bugfix release of Python 2.7, so it should be 100% backwards compatible unless your code depends on the existence of one of the bugs that was fixed.

It should be perfectly safe to go ahead and use 2.7.16.

Hello, @BryAB, and welcome to Python Foundation Discourse!

Are you perhaps planning to run some large software package that was written in Python 2.7.x, has not been ported to Python 3, and that is not convenient for you to upgrade? Otherwise, it would likely be in your best interest to use the most recent stable release of Python 3.10.

I am connecting an old Zeo EEG (Zeo Sleep Tracking - POLYPHASIC SLEEP | Sleep Right, Live Well) to my Raspberry Pi computer via a USB connection so as to extract the sleep stage and brainwave data from the Zeo EEG to my Raspberry Pi where I can then use the Raspberry Pi’s IO pins to activate external hardware that will generate different types of stimuli (e.g., tactile, visual, audio, etc.) during REM sleep in an attempt to induce lucid dreams. The Zeo EEG has API (Getting Started — Zeo Raw Data Library v2.0 documentation) that can be used for such purposes plus it is very comfortable for wearing while sleeping. Unfortunately the Zeo EEG is no longer commercially available, and the EEGs that are available will not interface via Bluetooth with the Raspberry Pi computer (or at least I do not know how to make them do so).

1 Like

Thank you very much for that information. I thought that maybe Python version 2.7.16 was a part of Python 2.7, but I could not find anything on the internet to verify that, and so I figured the Python experts on the Python forums would probably know. Thanks again!

That’s really cool and potentially very beneficial. Best of luck with this project!