5

I've never programmed in Python, but I recently came across an article talking about the differences of learning Python 2 vs Python 3 and committing to one version or the other.

What are the abstract level differences between Python 2 and Python 3 as it relates to hobbyists doing hobbyist things on the Pi and learning Python?

For example, does either provide a significant advantage or disadvantage to working with the GPIO, or other IO, of the Pi? Are any features of the Pi hampered, nerfed, or not present by using one version over the other?

Looking at the flavor text of the Python tag, it seems that I don't have to choose because both usually come with the OS. For some reason, that seems confusing.

4
  • This seems to be an inappropriate question for this site. You might have more luck on raspberrypi.org/forums
    – joan
    Commented Nov 7, 2017 at 23:13
  • Many people would argue that any version of Python is "nerfing" (as you put it), so in some sense the entire premise of this question is nonsense. (Raspberry Pi isn't pushing Python because it's "good" in any sense - They are pushing it because they think it's easy.) To the extent that there are, as you note, two "live" version of Python at the moment it probably depends on what you want to do and a matter of opinion, so I think that's ultimately off-topic for this site.
    – Brick
    Commented Nov 7, 2017 at 23:25
  • 2
    Personally I disagree with the other two comments about this not being a valid question for the site, I believe its a valid question for someone coming to the platform. Fundamentally this is a QA site about the pi platform. Considering the question was worded specifically towards RPI I have put in my answer, even though it would be the same answer regardless.
    – crasic
    Commented Nov 8, 2017 at 0:05
  • 1
    I think this question is framed for a Pi context well enough to not be off-topic and neither do answers to it need to be opinion-based. The existence of certain features (say libs for GPIO and the respective Python versions) or the lack thereof can be discussed quite objectively. Given that Python 2.x retires in 2020 I would however go so far and say: Starting Python now? Do yourself a favour and go for Python 3. If there are key libraries out there not available for Py 3 those should be migrated or you'll have to look for valid alternatives.
    – Ghanima
    Commented Nov 8, 2017 at 7:00

1 Answer 1

5

It's the same language, just a new version/revision of the standard and specification.The differences are subtle enough that you likely won't notice.

Languages are very formal, standardized things, like dictionaries, maps, or laws.

When the standard changes or a feature is added - usually after a long period of debate and discussion - this formal document is updated. Which triggers a new version number.

Python3 was a significant update to the existing standard so they went as far as to change the first number in the version field to indicate its significance. However, its "still python"

From the python.org page on 2vs3

What are the differences?

Short version: Python 2.x is legacy, Python 3.x is the present and future of the language

If it were me I would start learning from the current version, unless you have a compelling reason not too - like a must have library written for python2.


Details

What are the abstract level differences between Python 2 and Python 3 as it relates to hobbyists doing hobbyist things on the Pi and learning Python?

Practically None.

For systems engineering perspective (larger embedded projects), there are a few features in Python3 that make it a more suitable language for designing large systems.

For example, does either provide a significant advantage or disadvantage to working with the GPIO, or other IO, of the Pi? Are any features of the Pi hampered, nerfed, or not present by using one version over the other?

No, There is no significant advantage or disadvantage for one vs the other for learning or doing "hobbyist" things.

However, If there is a library, tutorial, or example you wish to try that supports one and not the other then start with that version

Python2 still has more support from libraries, and more code for it on e.g. github to use as example. But this is rapidly changing.

because both usually come with the OS. For some reason, that seems confusing.

It can be.

There are many system utilities and applications available that are written using python, often these programs work well, and are very well tested from many uses.

Porting to Python3 presents a risk that may not be worth the effort. As such many systems will package both python2 and python3 in order to run software that requires one or the other.

I would highly recommend that you learn to use virtualenv and pip to create local, customized installations of python on a per-project basis. The "system" python is intended to support installed programs and may not be the version you want to use

2
  • Very useful, could you provide some link about pip and virtualenv to learn? Thx Commented Nov 15, 2018 at 17:20
  • 1
    @PhilippeGachoud I can suggest a related answer of mine and a related stackoverflow question, as well as the python guide on virtualenv here. The basic rule of thumb is apt-get to install system packages, virtualenv + pip to install project(s) specific environments. pyenv is an advanced wrapper that allows even more configuration on top of virtualenv
    – crasic
    Commented Nov 15, 2018 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.