21

I'm starting a new open-source software in Python, and I'm wondering whether I should use Python 2.x or Python 3.x.

It will include a heavy GUI, complex scientific algorithms dealing with large amounts of data. I'll need at least Numpy, Scipy, PyQT4, PyOpenGL, h5py, optionaly Matplotlib. It should first be released in 2013, with updates and extensions during the next few years.

It will be used by scientists that do not necessarily have a background in computer science, on a wide variety of computers (Linux, Windows, Mac...). Some machines may be old.

If I choose Python 3.x, I fear that the software and the third-party libraries may be more complicated to install, especially on old systems where Python 2.x is already installed. It would be better if RPM-like packages (or Windows installers) for Python and the external libraries were available on most systems, such that one doesn't need to compile everything. Also, I don't know if the 3.x branch is mature enough.

If I choose Python 2.x, I may need to port the software to Python 3.x in the near future if the 2.x branch becomes deprecated (when will that happen?).

What would be the best option?

Cyrille Rossant
  • 488
  • 1
  • 6
  • 19
  • 3
    Of those dependencies, I think only PyOpenGL isn't ported yet. Matplotlib is ported but not yet released, though the release is due in a couple of months. The others (numpy, scipy, PyQt4, h5py) all have Python 3 releases already. – Thomas K Aug 13 '12 at 17:12
  • And python 3.3 in one month. By 2013 python 3.4 will be out from the oven, with 2.7 in maintenance mode... By the way, for windows you already have matplotlib binary installers in Golhke site. – joaquin Aug 13 '12 at 17:58
  • 1
    I disagree with the folks suggesting starting with 2.7. Take a look at your dependencies and see what does not yet claim 3.x support. Then look at how much effort it would be to port that. Do it. Problem solved & everybody loves you and you never need to convert your code from 2 to 3 in the future. – gps Aug 13 '12 at 20:28

3 Answers3

13

UPDATE: My original answer was given in 2012. However, now, years later, the answer should and must be Python 3.


This wiki discusses exactly your question: Should I use Python 2 or Python 3 for my development activity?

This is a very large subjective part to this question which depends on exactly your specific situation and constraints.

IMO, however, if you can't be sure that all 3rd party libraries you need will work with Python v3.x I would stick with Python 2.x but try to write code to be as compatible with Python 3.x as much possible (e.g., print() etc) so that if you ever need or want to migrate to v3 your work won't be so challenging. And of course there are documentation and tools on moving from version 2 to 3. And this on porting v2 code to v3.

This will especially be the case on systems where you don't have control or can't install newer versions of Python or customize the installation of 3rd party software/libraries.

Given that your software will be run on a wide variety of systems (Linux, Windows, Mac ..) and by a number of different users I still think that v2 is more of a common denominator these days.

So, short-attention-span summary: Use version 2.x but perpare your code for v3.x

Finally, if you put this search string "[python] version 3 or 2" into the SO search box, you'll find a number of related posts:

Levon
  • 138,105
  • 33
  • 200
  • 191
  • 1
    very like my answer in http://stackoverflow.com/questions/11372190/python-2-and-python-3-dual-development – Paulo Scardine Aug 13 '12 at 17:21
  • Doing print() instead of print() is completely pointless, as that kind of conversion is easily done with 2to3 once you need to do it. Making code compatible with Python 3 means not using deprecated modules or constructs and being very careful with bytes vs unicode vs native strings. – Lennart Regebro Aug 17 '12 at 18:21
7

Python 3. (The answer to this question has changed!)

Python 2 is for legacy projects. New projects should lean towards Python 3.

The reason for this is that Python 3 (now 3.6) is roughly getting a new release each year. It has also been stable for many years (is in its tenth release year!). In contrast, Python 2 (still 2.7) has changed little in the last several years and will continue to grow stagnant.

For more information: https://wiki.python.org/moin/Python2orPython3/

Robino
  • 4,530
  • 3
  • 37
  • 40
0

I agree with Levon.

With those requirements, I wouldn't risk starting in Python3 yet, but you should write your code taking as many of Python3 changes into consideration as possible.

See this question Writing Python 2.7 code that is as close to Python 3.x syntax as possible as it might help you with some imports and standards that you can use to make your code as future-proof as possible.

Also, if you're running in a variety of systems, you'd need to either distribute your version of python bundled in the application, or trust the installation of the user. Most OS's (non-windows), come with a 2.x flavor of Python installed, and it's not trivial for a non-techie user to upgrade to 3.x without the possibility of breaking the system.

Community
  • 1
  • 1
pcalcao
  • 15,789
  • 1
  • 44
  • 64