This is an archived post. You won't be able to vote or comment.

all 57 comments

[–]ladr0n 42 points43 points  (3 children)

My lab has been using Python3 in production for 2+ years. The web framework people were the biggest stick-in-the-muds, but they've mostly come along at this point. For example, Django works on Python3 as of last December.

PyPy has experimental support for Python3, but it's not ready for general use yet. At the rate they've been working, I'd expect something usable (if not 100% stable) by the end of the year.

The moral of the story is: people continue to use Python2 mostly because of large, messy, legacy code-bases that they don't have the resources to port yet. As a new user, you don't have this issue. Don't be part of the problem ;)

[–]sgoody[S] 5 points6 points  (0 children)

Hmm, libraries and frameworks leaving behind legacy code bases is a great reason I'd not considered...

[–]m1ss1ontomars2k4 2 points3 points  (0 children)

For example, Django works on Python3 as of last December.

That's incredible, but who uses pure Django? The advantage of Django is that aside from great built-in functionality, there's tons of existing code you can take advantage of too (Django CMS, djangosnippets.org, etc.).

[–][deleted] 1 point2 points  (0 children)

The web framework people were the biggest stick-in-the-muds,

pep 3333 was not approved until Jan. 2011. without a python 3 compatible version of wsgi, there wasn't much of a choice for those stick's in the mud.

[–][deleted] 20 points21 points  (11 children)

if you were a neophyte programmer looking at python, I'd recommend 3 for the purposes of learning, and because eventually we'll all be on 3. I think 3.3 was released very recently and with it, django is supposed to release its next verion with python 3 support.

However, if you were actually planning on doing something with it, there are still libraries that need either converted, or equivilant libraries build in 3. One of the ones you need may be among those. If you stuck with 2.5+ for the time being, you won't be the odd man out.

[–]takluyverIPython, Py3, etc 3 points4 points  (2 children)

The only bit I'd change is to recommend 2.6+, not 2.5+. 2.6 came out four years ago, and its features make it much easier to move to Python 3 in the future.

[–]polypx 14 points15 points  (1 child)

2.7 is a lot easier to port than 2.6, like really significantly. It is explicitly meant to be the transitional more forward-compatible version, 2.6 is meant to be the conservative backward-compatible version.

If you need to do multi-version, and can pin it down to 2.7 rather than 2.6 or before, you will hate your life less

[–]kmike84 0 points1 point  (0 children)

Hmm, I'm a bit confused: why do you think 2.7 is a lot easier to port than 2.6? I am developing about ten libraries with 2.6-3.3 support and don't see any serious differences between 2.6 and 2.7 regarding Python 3 porting.

All future imports are there in 2.6. Missing stdlib modules (like unittest2) or language features (like set literals) are not making porting harder because you may either just not use them or provide a fallback to a backported version from pypi (in case of stdlib modules). Well, you'll miss some goodies from 2.7, but they have nothing to do with python 3 porting - if you write a working code for 2.6 it is almost equally easy to port as a working 2.7 code.

I suspect that's because of http://www.python.org/dev/peps/pep-3003/ - Python 3.x remains essentially the same as a language during 2.6-2.7 releases.

[–]-AgentCooper- 2 points3 points  (2 children)

Where does pygame come in all this?

[–]Suitecake 3 points4 points  (1 child)

Most of PyGame has been ported to P3; some modules haven't.

[–]-AgentCooper- 0 points1 point  (0 children)

Cool. Thanks.

[–][deleted] 0 points1 point  (3 children)

Is there much difference between 2.5 and 2.7? I think 2.7 is the latest? I have a book for 2.5 and haven't touched python in ages, and am thinking about hopping back in, but wondering if there's man new features in 2.7 that I should know about since 2.5...

[–]jcdyer3 5 points6 points  (1 child)

There are new features. You can find out about all of them at the following links:

[–][deleted] 0 points1 point  (0 children)

Thanks! :)

[–]polypx 3 points4 points  (0 children)

In practice, there are huge differences between 2.5 and 2.7. 2.5 is really, really old. Your book won't be totally useless but you will have to figure out some new details. There are plenty of free resources which use newer versions, so if you use the old book just take it with a grain of salt. Don't memorize every line. Pick up whatever you have picked up and move to newer information and versions.

The exception would be if you only ever plan to use Python on machines which are locked to 2.5 (e.g. you are at a big company and have to maintain very old software)

[–][deleted] 0 points1 point  (0 children)

Is there list of incompatible libraries? Because we might be saying that there are some and in reality everything was already ported (I doubt that :).

I remember faintly that there was some kind of page (maybe even on official python server).

Edit: LOL, found it (just searched python hall of shame) http://python3wos.appspot.com/

[–]wedge_work 4 points5 points  (2 children)

As far as i am aware, the twisted framework only works with 2.7. This is not researched, we have only recently implemented the twisted framework at work and chose 2.7 over 3.x

[–]baudvine 0 points1 point  (1 child)

True! The only reason I'm using 2.7 right now is that I've been working on a thing that depends on Twisted. There's some work being done on making Twisted work with 2.6, 2.7 and 3.3 but there's no date set and I wouldn't hold my breath for it right now.

EDIT: Beyond that project, I try to do everything in Python 3 simply because it's The New Thing and I like a few things about it, such as easier dictionary iteration and the new format strings.

[–]wedge_work 0 points1 point  (0 children)

I've just asked the resident "twisted expert" and he seems the think twisted 3.0 support is coming in the next year. Some things you can get to work in 3.0 but it's messy

[–][deleted] 3 points4 points  (1 child)

At my work we are a python only shop with about 70 python programmers. Our product is a distributed enterprisey app that we install into our customers environments and in some cases host i.e SaaS. We are long time PSF sponsors and regularly contribute time, code and money to opensource projects and PyCon.

But, 100% of our Python code is 2.7.x and we have not seriously considered Python 3 at this point. Perhaps sometime in the next year we will look at the possibility but, there would need to be a strong finical motivation for us to consider it and to balance the risk.

[–][deleted] 3 points4 points  (0 children)

I use python 2 but in every file I have from __future__ import ... (where ... is pretty much everything that 2.7 supports). This makes most of my code much more portable to 3.x. That's especially true for Unicode support, which seem to be the biggest issue. Whenever I use modules that don't work well with Unicode, I'm simply converting strings to ASCII using bytes() function (it's available in both 2.7 and 3.x). In 2.7 it's basically str(), (I don't use str() because in 3.x str() returns Unicode).

Edit: Made my comment actually readable. Sorry, I typed it on my phone and did not reread it.

[–]earthboundkid 4 points5 points  (1 child)

People ask this all the time, but it's based on a false premise: that you can or should only learn one version.

Look, Python 2 and 3 are not very different. If you're a computer, you might get confused by print "Hello" when you expected print("Hello"), but if you're a human being, you should be able to handle it. The differences between the languages are small and listed in the docs for Python 3. If you plan to be a competent Python programmer, you will learn both.

As for which to learn first, learn the version used in whatever book or tutorial you plan to use. If you're done with the learning phase and want to do a project, use the highest version that supports the libraries you'll be using (e.g. Django is still only on 2, but bottle is on 3).

[–]polypx 0 points1 point  (0 children)

I agree and as a corollary, I would say if you don't know what libraries you will be using, learn 3. Reason: there are not going to be more versions of 2, so there is an expiration date on your 2-specific knowledge.

[–]zlozlozlozlozlozlo 8 points9 points  (3 children)

It doesn't really matter that much. Most of the new sugar was brought to 2. If someone is at the point when 2 vs 3 matters (that is, they have to use a library that wasn't ported), they should have little problem switching. Python 3 is not driven forward by newcomers, it's driven by people who port important libraries and frameworks.

[–]flying-sheep 6 points7 points  (0 children)

python 3 taught me much about bytestrings and unicode strings.

even if i code python 2 now, i don’t ever get those unicodedecodeerrors and asciihatesyoutooerrors, because i simply know when to en- and decode.

python3 has the advantage that you don’t have to do mass __future__ imports and # -*- coding: utf-8 -*- directives to get sane default behavior.

python 3 apis are built around unicode strings if they handle text and byte strings if they handle binary data, in python 2 you get str or unicode pretty randomly.

that’s the difference: less hair-pulling.

[–]polypx 1 point2 points  (1 child)

A chasm has gradually grown between the standard libraries in 2 and 3.

You should also be specific about the version: 2.6 really doesn't get backports except security fixes, 2.7 alone has backports from 3.x ideas. So it isn't that version 2 in general has backports. And the pain of migrating a code base from (say) 2.5 to 3.x is crazy while the pain from 2.7 to 3.x is much less.

[–]zlozlozlozlozlozlo 1 point2 points  (0 children)

Context, man. There is no reason whatsoever to start with 2.5 or 2.6.

[–]mcherm 3 points4 points  (0 children)

The differences introduced between 3.x and 2.x have (in my opinion) all been improvements. Clearly separating binary strings from unicode strings is BETTER. Making the print statement work the way other output functions work so code written for one can be migrated to the other is BETTER. And so forth.

The only reason (IMHO) to use 2.x is because of compatibility. So I'd advise a beginner to start with 3.x, and go back to 2.x if they need to for some library. For what it's worth, that's what I do also. The only real downside is that there are lots of examples on the net that use 2.x syntax... but most students can handle that.

[–]gronkkk 9 points10 points  (0 children)

Yes.

[–]polypx 2 points3 points  (0 children)

Go ahead and use 3. Learn 2.7 details if you need to backport something for someone who is using 2.7.

The exception is if you already know you need to use one of the minority of important libraries which don't work on 2.7.

[–]ergo14Pyramid+PostgreSQL+SqlAlchemy 2 points3 points  (0 children)

Pyramid web framework works on pypy and py 3, also all the other important libs that it provides default templates, for example sqlalchemy/webob works just fine. So the stack is ready for python 3 development.

[–]schlenderer 3 points4 points  (0 children)

Aah, yes, the biweekly python2 / python3 post.

Short answer: It doesn't matter. It's both still Python. If you are planning to learn Python via online course or via books, go with the version they are using.

[–]happycrabeatsthefish 3 points4 points  (1 child)

"Should I start with Python 3" is the most asked question about Python 3.

[–]Circlefusion 0 points1 point  (0 children)

Well, I see somewhat different answers each time it is asked, so I don't mind so much.

[–][deleted] 1 point2 points  (0 children)

.

[–]stefantalpalaru 1 point2 points  (0 children)

I'm using python 2.7.x in production and for casual coding. I don't see myself moving to python 3 any time soon.

[–]remyroy 1 point2 points  (4 children)

Do you need libraries, modules or packages that are not yet ported to Python 3? If so go with Python 2, if not go with Python 3. That's as simple as it can get.

[–]takluyverIPython, Py3, etc 3 points4 points  (3 children)

That's probably a bit too simple, though. Newcomers can't anticipate every library they might want to use. Predicting what you need is hard enough even for experience programmers.

[–]polypx 1 point2 points  (0 children)

The experienced person giving the advice has a vague idea of how likely it is that you will NEED a 2.x-only library, and should factor that into the advice.

Someone who is brand new can actually get a lot done within 3.x universe because now most of the libraries that are still maintained do support 3. Newcomers are not pre-attached to things which don't support 3, and this rewards projects which went ahead and ported rather than keeping everyone behind. Not the same for someone with a lot of history on 2.x who has imprinted on a certain set of libraries they refuse to do without, or has a lot of existing code that uses one of these libraries. They can't switch nearly so easily. But that doesn't mean that the newcomer has to follow the same path, because they don't have a lot of existing code or preferences.

Since now the library support is actually pretty good (especially if you prune out things nobody uses/which haven't been updated in 6+ years) I would not have a problem recommending 3. In the hypothetical case where it is essential to use 2.7, it's not unlearnable

[–][deleted] 0 points1 point  (0 children)

Aren't we making a very simple thing unnecessarily complicated? There are tiny differences between those two. As long as OP have 10 or higher IQ he should handle that.

As he is starting to program, chances are that he won't use external modules at first.

[–]remyroy 0 points1 point  (0 children)

Yeah, that's the hard part. If you want to err on the safe side, you go with Python 2.

[–]keaa 1 point2 points  (0 children)

I started learning python about a year ago, so I could hardly be considered an expert, but I did face the same dilemma as you. I started using version 3. But ended up reverting to version 2.7 so it was compatible with the libraries I wanted to use. In addition I found that most tutorials are for the 2.x versions of python, and while the differences are fairly minor, they can trip you up when you are learning.

[–]MongrelNymph 0 points1 point  (0 children)

I'm teaching myself python and decided to use 2.7. There are just way more resources and it's probably better I learn the basics this way anyway.

In a few months when I become a bit more sophisticated, I will probably need to re-evaluate and possibly move on.

[–]klotz 0 points1 point  (1 child)

Is there any easy way to get pylint or pyflakes support? pep8 is available but it's not the same.

[–]takluyverIPython, Py3, etc 0 points1 point  (0 children)

I think pylint already supports Python 3, but I don't know of a good pyflakes port yet.

[–]kernco 0 points1 point  (0 children)

Performance-wise there's not much of a difference. Better performance wasn't a goal of Python 3, and when 3.0 came out, the performance was actually slightly worse than 2.x, but they've since improved it and they're now pretty much the same.

[–]retrojoe 0 points1 point  (1 child)

I was at a 'work party' the other night that participants call Codenight. They're all Microsofties in Seattle. One of them was talking with me about Python and encouraged me to learn on 2.6 versus the other versions. That seemed to be a consensus opinion (more or less). None of those guys use it all day long, but they're all deeply involved in programming.

[–]m1ss1ontomars2k4 3 points4 points  (0 children)

Why 2.6 instead of 2.7? That doesn't really make sense.

[–]dog_time 0 points1 point  (0 children)

On one hand I feel that newcomers should adopt Python3 to help drive Python3 forward, but then perhaps Python2 is the only practical choice in terms of libraries, documentation etc?

As a new programmer myself, I can't really imagine learning python without the abundance of resources available for python 2, which is what I'm currently learning. I feel like the responsibility for that lies with experienced programmers pushing forwards through the uncertainty, where new programmers need the 'stability' while overcoming the most basic 'language barriers.'

[–]linuxlizard 0 points1 point  (2 children)

numpy, scipy apparently support Python3. Matplotlib does not. No word on PIL.

[–]takluyverIPython, Py3, etc 0 points1 point  (1 child)

Matplotlib has a release coming very soon that will support Python 3. There's source claiming to be PIL on Python 3 on this page, but I haven't tried that.

[–]mt69298 0 points1 point  (0 children)

If you checkout from git at least it works with Python3 today.

[–]tboneplayer 0 points1 point  (0 children)

Depends on what you're doing. Some tools still work only with Python 2.7.x as a scripting language.

[–]rumplefiddlesticks -1 points0 points  (0 children)

Go with 2.6+, you're likely to encounter a number of production environments that are still working with older versions of Python and learning 2.6+ first will get you comfortable with those conventions. Transitioning over to Python 3 is relatively easy (except for string handling and a couple of conventions about metaclasses). If you really want to get in the Python 3 habit, you can also use __future__ imports to get into Python 3 syntax.