Python 2.7 or Python 3 (for speed)? [closed] - python

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 9 years ago.
I've looked around for answers and much seems to be old or outdated. Has Python 3 been updated yet so that it's decently faster than Python 2.7 or am I still better off sticking with my workable code?

The issue isn't about speed -- they're either the same speed or Python 3.x is faster (depending on which benchmarks you look at). More specifically, Python 2 used to be faster, but apparently, they're on par with each other now (?). See the comments and this slide deck (towards the back).
The core devs are also actively working on optimizing Python 3 -- each new release of Python 3 has been faster than the last. You can keep abreast of the latest proposals and ideas on optimizing Python (as well as the many complications) by monitoring the python-dev mailing list.
Rather, the reason many people used to give for not updated is because when Python 3 came out, and for several years after, the majority of Python libraries were not updated to work on Python 3.x. However, thankfully, this situation is vastly improved today -- the majority of 3rd party libraries are now Python 3 compatible.
The Python FAQ contains more info. You can also check the Python Wall of Superpowers or Py3 Readiness to get an overview of which popular Python libraries are currently compatible with Python 3.
Update: (Summer 2017)
I feel somewhat obligated to note that support for Python 2 is formally ending in 2020.
Many 3rd party libraries are also planning on following suit -- a large subset of the scientific ecosystem (e.g. matplotlib, pandas, ipython) are planning on dropping support for Python 2 in 2020, Django is dropping support... I wouldn't be surprised if other libraries do the same.
So, if you're interested in making sure you can use the latest and greatest features in either Python or your favorite library, you should look into migrating to Python 3 sooner rather than later.
Here are some guides on converting Python 2 to 3 code:
https://docs.python.org/3/howto/pyporting.html
http://python3porting.com/
https://eev.ee/blog/2016/07/31/python-faq-how-do-i-port-to-python-3/

FYI, here's a performance benchmark comparing Python 2.7 with Python 3.3. Python 3.3 comes faster than Python 2.7.

Python 3.3 included an optimization for Unicode strings that reduced their memory consumption. That might translate into faster code if more of it fits into cache.
Really the only way to know is to benchmark your most critical code in both and see what the difference is.

The necessity of Libraries for your applications will determine whether Python3 or Pyhton2 is better.

Related

Different version of python installed [duplicate]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
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?
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:
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/
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.

Best setup to develop cross-platform GUI-based apps using Python [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have been using REALbasic for a number of years to develop cross-platform apps. I have become frustrated developing with a proprietary language and so have decided to change languages and have settled on Python and QT.
Since I know no Python, would people recommend Python 2 or 3?
I think I will be using PyQt or PySide. I know that of these two, only PyQt (currently) supports Python 3. Does this give enough of an advantage over PySide? It's just that PySide seems to have a 'cleaner' syntax.
PySide and PyQt4 are almost identical. In fact, you can often replace PyQt4 with PySide (and vice versa) in your code's import declarations.
Python2 and Python3 are almost identical as well, with a few minor changes that a beginner won't notice for a while (aside from print being made a function).
Python2 has more support in terms of modules (Python3 broke backwards-compatibility with Python2), so I'd suggest you use Python2 until you figure out a reason to switch to Python3. There really is no benefit, as both releases are maintained separately.
In short, stick with the stuff that's known to work.
PyQt and PySide are mostly identical. The major difference is the licensing. PyQt is GPL, and when selling an app, it requires a commercial license, where PySide has a LGPL license allowing you to sell your code without buying a license. Nice thing is, you can just switch the imports and sell it. :) PySide is also 2.x only, where PyQt is both.
PySide funding is ending as well.
"It's just that PySide seems to have a 'cleaner' syntax."
PyQt uses api 1 in 2.x (switchable to api 2 using sip.setapi(2, 'item')), and api 2 in 3.x. Switching to api 2 will have the same syntax as in PySide and PyQt in 3.x.
A nice article explaining differences between api 1 and api 2 can be found in PSEP 101.
"Since I know no Python, would people recommend Python 2 or 3?"
You're more likely to use Python 2 as very many modules and libraries haven't yet made the switch to Python 3, as it was an incompatible release against Python 2 (it's been 3 years since 2008 when Py3k came out!).
Just go with which one fits your best needs considering the circumstances. Some people like PyQt more because it's been around longer, is a more mature project, and is likely to be more stable because of that. Although, I've never really had any problems with PySide either, so it should be fine.
On the question of "Python2 or Python3?", I would suggest you read this article on the Python Wiki. As well as giving detailed answers to most of the main questions you might have on this topic, it also has a lot of links that you will probably find useful.
As for "PyQt or PySide?": from a pure coding point of view, the differences are minimal, especially to a beginner (for details, see this artical on the Qt Wiki). The only significant difference between PyQt and PySide is licensing (GPL vs LGPL).
PyQt is a much more mature project than PySide, and is more flexible when it comes to compatibility with Qt and Python versions. The Sip package (which PyQt depends on), also allows you to fine-tune the use of different API versions at run-time (see here for details).
Overall, the "safest" short-term choice would probably be PyQt+Python2. There is a lot more code out there for PyQt than there is for PySide, and for Python2 than there is for Python3, and it is likely to stay that way for quite some time. So, as a beginner, it will do you no harm to start with that combination, as (leaving licensing issues aside) it will be relatively painless to make the switch later on if necessary.

Make the Move to Python 3 - Best practices [closed]

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 9 years ago.
We think about whether we should convert a quite large python web application to Python 3 in the near future.
All experiences, possible challenges or guidelines are highly appreciated.
My suggestion is that you stick with Python 2.6+, but simply add the -3 flag to warn you about incompatibilities with Python 3.0. Then you can make sure your Python 2.6 can be easily upgraded to Python 3.0 via 2to3, without actually making that jump quite yet. I would suggest you hold back at the moment, because you may at some point want to use a library and find out that it is only available for 2.6 and not 3.0; if you make sure to cleanup things flagged by -3, then you will be easily able to make the jump, but you will also be able to take advantage of the code that is only available for 2.6+ and which is not yet ready for 3.0.
For each third-party library that you use, make sure it has Python 3 support. A lot of the major Python libraries are migrated to 3 now. Check the docs and mailing lists for the libraries.
When all the libraries you depend on are supported, I suggest you go for it.

Production ready Python implementations besides CPython? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Except for CPython, which other Python implementations are currently usable for production systems?
The questions
What are the pros and cons of the various Python implementations?
I have been trying to wrap my head around the PyPy project. So, fast-foward 5-10 years in the future what will PyPy have to offer over CPython, Jython, and IronPython? and
Migrating from CPython to Jython
already shed some light on the pros/cons on the topic. I am wondering now, if those more exotic implementations are actually used in systems that have to run reliably. (possible examples? open-source?)
EDIT: I'm asking for code that needs the Python version >= 2.5
CPython
Used in many, many products and production systems
Jython
I am aware of production systems and products (a transactional integration engine) based on Jython. In the latter case the product has been on the market since the early 2000's. Jython is a bit stagnant (although it seems to have picked up a bit lately) but it is mature and stable.
IronPython
This is the new kid on the block, although it does have some track record in products. It (particularly version 1.x) can be viewed as stable and ready for production use, and development is officially funded by Microsoft, who appear to have an interest in dynamic languages on top of the CLR. It is the greenest of the major python implementations, but appears to be reasonably stable.
Stackless Python
This is used extensively in EVE Online, and they seem to view it as production ready. Bear in mind that Stackless Python has been around for something like 10 years.
At least one product, Resolver One, is said to be production-level and is totally based on IronPython.
Resolver One is a program that blends a familiar spreadsheet-like interface with the powerful Python programming language, giving you a tool with which to better analyse and present your data.
I know that Jython is pretty mature and has been around for a long time.
Also, I'd take a look at Stackless python
You can check http://www.portablepython.com/ which is the portable version of CPython. It is also bundled with very common and useful libraries and even an IDE, all portable.
There was Pyrex, which can be found at http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/. It is not Python, but very close. The Cython (not CPython) is based on Pyrex and can be found at http://www.cython.org/. They are both useful for creating C extensions for Python. Their languages are so Pythonic.

Python Version for a Newbie [closed]

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 am extremely new to python, having started to learn it less than a month ago, but experienced with some other programming languages (primarily C# and SQL). But now that Python 3.0 has been released and is not backwards compatible, what would be the advantages and disadvantages of deciding to focus on Python 3.0 or Python 2.6?
Go with 2.6 since that's what most libraries(pygame, wxpython, django, etc) target.
The differences in 3.0 aren't that huge, so transitioning to it later shouldn't be much of a problem.
Since they have incompatibilities, I suggest you start going for Python 3.0 which is more useful in the future anyway. It's a better language. You can see the precise differences in What's new page on its Web site.
I would say begin with 2.6 since the vast, vast majority of documentation regarding Python will be applicable to 2.6 as well most open source projects you may want to contribute to will be in 2.6 for awhile. Then, once you have a good foundation in 2.6, you can learn 3.0. That way you can kind of appreciate how the language has evolved and where the "aesthetic" of the code comes from.
Start with 2.6, and when you get a bit more proficient with the language (few thousands of lines of code written), transitioning to 3.0 will be easy and natural. While learning I suggest you ignore classic classes, and pay special attention to iterators, generators, and list comprehension.
It depends on what you are willing to do.
Python 3.0 is the newer release, and with time should become the standard.
However, it has almost no libraries or frameworks available, and even the tools are not so up to date (e.g. the Eclipse plug-in for Python is still in the migration phase).
On the other hand, there are no huge differences, and once you learn one, moving to the other is quite easy.
So, if you plan just to play around, you can go with 3.0.
If you plan to use it on a new project, I would stick on an older release.
Be careful though. Libraries such as the mysql driver are still in 2.5
If you're looking at it from a getting-a-job perspective, I'd definitely at least learn 2.x as well. The code I work on is still targeting python 2.4 and to the best of my knowledge there is no plans to move to even 2.6, let alone 3.0 in the near future. There will be a ton of 2.x python code floating around for years to come and the vast majority of python jobs will involve working with that code.
So I'd start by learning python 2.6 while the whole time keeping an eye on 3.0 so that you are at least aware of what bits of your 2.x code won't work in 3.0

Categories

Resources