This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
Is it advisable to go with Python 3.1 for a beginner?
What version of Python should I use if I’m a new to Python?
Haven't really made anything in Python... Which Python should I take ahold of? 2.X or 3.X?
2.X still offers a far wider variety of third-party libraries / frameworks, instructional websites and books, and experts to help you out -- I expect this will continue for a few years until 3.X gradually overtakes it. Right now, therefore, I would still recommend 2.X despite 3.x's even-greater "clean-ness" and simplicity (because some cruft which 2.x has to keen around for backwards compatibility was finally wiped out in 3.x). Very few new features of 3.x are not backported in 2.x, by the way -- e..g, if you want print to be a function, like in 3.x, in your 2.6 or 2.7 module, just put, at the start of the module, the statement
from __future__ import print_function
"Importing from the future" is a typical Python way to make new features available when explicitly requested, without breaking backwards compatibility.
You are in luck! Due to a lot of confusion about this people have put together a wiki page in the last few days: Should I use Python 2 or 3?
I'd say it depends where you are going to run the code. If you have complete control over the environment, use 3.x. If your environment is controlled externally (cheap webhosting for example) then you will probably need to use 2.x. The only other reason to stick with 2.x is if a critical library you can't live without hasn't been ported to 3.x yet. Don't saddle new code with 2.x-isms if you can avoid it.
2.x
Quite some modules have not yet been ported to python 3 and you will find much more books, online resources for learning python 2.x
You also can't rely on python 3 being preinstalled, while for most linux distributions you can rely on some version of python 2 being available. The only one I know of that already has python 3 packages is the latest Fedora 13. If that matters to you depends on your needs.
See also this related (though not identical) thread on Python 3.0.
While I think the case for 3.x is more compelling than it was a year ago, it still doesn't have the breadth of third-party library coverage of 2.x. I would suggest developing for 2.6 and making use of the migration utilities when the time finally comes (e.g. some dependency is forcing you) to move to 3.x.
If you are just learning Python (and you don't have a specific project you need to complete), I'd suggest that you start with the newest version (3.x). Even if you start with 2.x, though, the basics will be the same, so you will be able to learn any differences in 3.x very quickly.
Go with 2.x
I ran into a lot of compatibility issues with libraries and Python 3.x, although I can't recall which ones specifically. The specific issue I was seeing had to do with unicode strings, which I understand is the default in Python 3. The library threw an exception when using unicode strings, and returned an error for normal ASCII strings. This was about 6 months ago, and I'm assuming the support hasn't drastically improved since then.
If you're absolutely sure you won't use any external libraries, 3.x might not bite you. As a compromise, you could use 2.x and try to avoid the changes in 3.x to make it compatible.
Related
I'd like to upgrade to python 3.5, but I use legacy python 2.7 packages. Is it easy to run legacy packages in python 3.5? I have been under the impression that this isn't easy, but I did a few searches to see if I'm wrong and didn't come up with much.
I would expect there to be a multiprocessing package that allows standardized hand-offs between 3.5 code and 2.7 packages, allowing them to run independently under their own environments, but being somewhat seamless to the developer.
I'm not talking about converting my own code to 3.5, I'm talking about libraries that I use that won't be updated for or by me.
If you used the newer syntax supported by 2.7, e.g. around exceptions, and/or, better yet, worked with new features imported from __future__, you'll have much easier time converting your code to Python 3 (up to no changes at all). I'd suggest to follow this path first, for it can be trod gradually, without an abrupt jump to Python 3.
I suppose Python processes with different versions can interoperate, because object pickling format is compatible, and you can explicitly use a specific pickling protocol version on both sides to ensure that. I don't think multiprocessing packages on either side would be too useful, though. Consider using e.g. ZeroMQ as a more general solution.
Unfortunately there is no "nice" or automatic way of handling the processing of 2.7 code under 3.5 (that works perfectly).
You mentioned that you are concerned about libraries, not your own code - firstly, you'd hope that if they are under active development, they will be updated. If not, as you stated, then there is a possibility that they were written to be future proof. I've found some good ones are (e.g. google-api-python-client, e.g. https://github.com/google/google-api-python-client/blob/master/setup.py).
Failing that, the only way to upgrade is to fix all the syntax changes yourself. Most common ones I deal with are around 'print' and exception handling.
I've dabbled a little bit in Python - not much beyond modifying other people's scripts. Now I'm considering getting into it for real, and have hit the "Choose whether to learn 3.x or 2.x" dilemma. I've read that the main issue with 3.x is the existence of a lot of legacy 2.x code which won't run with 3.x ... but that was a while ago. Is it still the case that backwards-incompatibility is an important consideration against working in Python 3.x?
Note: A similar question was asked 5 years ago:
Is it still too early to hop aboard the Python 3 train?
In my experience, there's only a handful of libraries that are needed for using Python in the real world, and all the major ones have been ported for years and years. Most of the Python 2 only libraries are ones that have become stagnant and are no longer updated (there are probably exceptions, but none that I'm aware of).
The real question, though, is are there any libraries that you need that are Python 2.7 only? If the answer is "No" or "I don't know" then I would definitely suggest starting on Python 3.
Another factor is that it's usually quite easy to take Python 3 code and change it to run on Python 2 (if the need arises), since Python 2.7 has a lot of forwards compatible features. The reverse, taking Python 2 code and porting it to Python 3, is not nearly so clean.
As said in python official documentation
Python 2.x is legacy, Python 3.x is the present and future of the language
And you can check this web app here (or this as #Peque suggests) for python3 library support.
I am interested in learning Python but I don't know which version I should chose. When I Googled, I got answers posted over a year ago. If I want to learn Django, which version will be useful and will get support?
Note that I know C, C++, Java and C#.
Django only has experimental support for Python 3, so you'll have to go with Python 2.7 for now.
First, a short comparison is It's Better than 2.7 and When should Python 3.3 become the default. However, remember that Python is in fact a script language and you can use C or C++ in doing modules with new capabilities.
I would recommend to start with python 2.7, it just more commonly used nowadays, and django is written in 2.7 AFAIK.
Apparently the answer you found still holds:
Should we use python 2.6 or 2.7 or 3.x?
If you already know several languages then learn both Python 2 and 3. The difference is small enough to allow many projects to support both versions using single (the same) source code.
For actual deployment you might prefer Python 2.7 if you need to use dependencies that are not ported to Python 3.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why?
[Edit 03/10/2014: This answer is now out-of-date. Django has supported Python 3 for some time.]
[However, it must also be noted that the django third-party packages and extensions used in many Django projects are in various stages of Python 3 compatibility implementation. More details can be found in Django packages website which tracks the statuses of various projects.]
Django has not moved over to 3.0. That is all I need to know.
Related Questions
Will Python 3.0’s backwards-incompatibility affect adoption?
Is Python 3 a good starting point when you want to learn Python?
If I’m going to learn Python, should I learn 2.x or just jump into 3.0?
Who’s Using Python 3.0?
Python Version for a Newbie
Is it worth learning Python 2.6 with 3.0 coming?
Most of the answers in these questions echo the same sentiments. Aside from Django, too many frameworks/libraries - WxPython, PyGame, Django, etc - have still not adopted it. I'm sure as hell not making the move until they do.
Because major libraries that my codebase depends upon have not released a 3.x version. (wxPython, matplotlib, numpy, etc.)
So the responsibility goes upstream from my point of view.
If all my dependencies were 3.x compatible, I'd probably have switched by now.
Compiled 3rd party modules haven't updated.
Different syntax
Slower integers.
The #python IRC channel on freenode has in its title that its too early to switch.
3rd party tools and libraries. I'm having trouble making some things work under 2.6 (not a LOT of trouble, mind you, but some.)
As I see it, the ecosystem is one of Python's biggest strengths, and going to 3.0 at this point chucks a lot of that out the window. (In a year, I'm sure the story will be totally different.)
(Obviously, there's a chicken and egg problem here, but fortunately it's not my problem to solve, so I'll stay with 2.6 for a while.)
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
I think you answered your own question here. The lack of backwards compatibility makes 3.0 a much harder sell than a seamless upgrade because you have to adjust your thinking and discard some programming techniques to use the new version.
Call me back when they have an upgrade script for my brain.
Because the default installation of 2.5 on Mac OSX Leopard works just fine. I have no need to upgrade and I see no advantage to upgrading except an end to the woes of unicode.
If you are interested to move to Py3k one interesting way would be to write code in Py3k and use a 3to2 script which is being written now as a part of Google Summer of code project, on the lines of 2to3 script.
The operating system I use the most, Debian, does not have a Python 3 package, not even in the "unstable" (brand new) branch. Unless I compile it myself (which is quite 20th century), it means no Python3 to me.
I bet it is the same issue with many operating systems.
Unfortunately, for the same reason as most others have said - 3rd party libraries still not having been made 3.0 compatible.
For this reason, as well as that some GNU/Linux distributions (Ubuntu in my case) still comes with Python 2.6, I can't completely throw 2.x out the window yet.
However, the change to 3.0 is not a major one IMO. Except for "print" being a function and the new string formatting system, it's really more or less the same as before.
In fact, I find that most of my old scripts (those that do not depend on 3.0 incompatible 3rd party libraries) will work flawlessly in 3.0 after I update all the prints and string formatting. In some cases I've also had to change some module names (specifically stuff from the "email" module), but other than that nothing major.
Also, all the scripts I have updated for 3.x compatibility so far still seem to work flawlessly in 2.6 (but not older 2.x of course, as they lack the new 3.x syntax).
The main reason I am not switching is that so many books and coding challenge websites are still 2.x. I installed 3.x and realized very quickly that I had to uninstall and go to 2.x.
Because of the lack of backward compatibility, switching is hard, especially if there is C code involved. And although I understand the unicode/string thing may be very useful to some people, I certainly don't care about it myself.
Basically, Py3k did not solve many problem that I care about (distribution issues, versioning of modules, simplified import model).
Python 3+ does not support numpy.
Correction: it now does. As it now supports mathplotlib.
I am just learning python on my ubuntu 8.04 machine which comes with
python 2.5 install. Is 2.5 too dated to continue learning? How much
of 2.5 version is still valid python code in the newer version?
Basically, python code, for the moment, will be divided into python 2.X code and python 3 code. Python 3 breaks many changes in the interest of cleaning up the language. The majority of code and libraries are written for 2.X in mind. It is probably best to learn one, and know what is different with the other. On an ubuntu machine, the python3 package will install Python 3, which can be run with the command python3, at least on my 8.10 install.
To answer your question, learning with 2.5 is fine, just keep in mind that 3 is a significant change, and learn the changes - ask yourself as you code, "how would this be different in 3, if at all?".
(As an aside, I do wish Ubuntu would upgrade to 2.6 though. It has a nice compatibility mode which tries and points out potential difficulties. But python is in such big use on a modern Linux distro, it can be a difficult change to make)
Here's an article describing 2.6 -> 3's changes
Python 2.5 will be fine for learning purposes. In the interest of learning you will probably want to look into the differences that python 3.0 has introduced, but I think most of the Python community is still using Python 2, as the majority of libraries haven't been ported over yet.
If your interested in 2.6 here is a blog post on compiling it on Hardy, there may even be a package for it somewhere out there on the internets.
Follow up, if there is a package I'm not finding it. Self compiling is pretty simple for most things, though I've never tried to compile Python.
I don't think it is 'too dated' to use, but there are some really nice features in python 2.6 that make it worth the update. This article will give you the details. As long as you have control of the machine, it is worth it.
I don't have any statistics but my impression is that Python 2.5 is the version most in use today. It is certainly not "dated" - I still use Python 2.5 and I expect that I will be using it for weeks or months yet to come.
If you have Python 2.6 available, though, I would suggest upgrading, as it's still fairly similar to Python 2.5 but will put you in better position for using Python 3.
Also, right now the 2.x branch is the most supported one, so I would also say that it's a good reason to start with that version.
And when the moment comes, you can always switch to Python 3.
Python 2.5 is fine. There are still plenty of people on Python 2.4 and 2.3.
One thing to keep in mind about python 2.6 is that some libraries may not work. Numpy comes to mind..