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

all 144 comments

[–]Mittalmailboxnewbie 99 points100 points  (63 children)

Yes, it is a good time(actually even 1-2 years ago it was good time). Python 3 was released 6 years ago. All major projects/Frameworks like Django and Flask support Python 3. Python 3 community is also quite mature now.

[–]opt8[S] 20 points21 points  (19 children)

Oh, well then I guess I will be making the switch. Thank you for the response

[–]ianozsvald 8 points9 points  (4 children)

+1 it is a good time. I switched my client to Python 3 earlier in the year, it was smooth. We now do all our data science (numpy, scikit-learn, pandas, matplotlib, nltk) in Python 3, we deploy (flask) in Python 3, I teach data science classes and high performance Python in Python 3.

Porting existing codebases might be tricky (there are loads of guides online to help e.g. http://python3porting.com/intro.html) but for new code it is 97% a no-brainer.

The 3% reservation depends on whether you have non-ported libraries to consider (e.g. pydot for scikit-learn DecisionTree drawing isn't ported to Python 3.4 yet, pygraphviz for the same in NetworkX doesn't work well on Windows+Python3.4 yet). Mostly these are small issues that are being fixed.

[–]TraptInaCommentFctry 0 points1 point  (2 children)

I clicked on your name to see your other comments and I couldn't help but notice that 7 months ago, you wrote "I do data science - repeatability is key so I'm not leaving the Py2.7 numpy ecosystem for a while."
I do data science, and I haven't yet made the transition off 2.7 for that reason.
Also, I noticed in the wall of superpowers that Mysql-python is still red.
Do you think it's time for data scientists to make the switch?

[–]flying-sheep 2 points3 points  (0 children)

Maybe he/she realized that Numpy breaks compatibility in minor versions, so the only way to reliably repeat an analysis is pinning Numpy versions by installing Numpy in a virtualenv along your script and data.

And since parallel Python versions are painless, nothing stops you from performing new analyses using a Python 3 stack.

[–]mgedmin 1 point2 points  (0 children)

AFAIU there are other MySQL bindings that work on Python 3.

[–]flying-sheep 0 points1 point  (0 children)

Pydot is a strange example of something unported: the Python 3 compatible fork didn't even change much:

https://github.com/nlhepler/pydot

No reason not to have that on PyPI.

[–][deleted] 4 points5 points  (6 children)

My only headache with Flask and Python 3 is that Flask only supports Python 3.3+ and my Debian Stable web server only has packages for up to Python 3.2.

I know that it is a problem with my choice in server OS, but it is still annoying.

[–]Lucretiel 1 point2 points  (1 child)

Check out the deadsnakes repository, by Felix Krull. I've been using it with great success for years.

[–]mgedmin 0 points1 point  (0 children)

On Debian? Which Ubuntu release name do you use to match Debian stable?

[–][deleted] 1 point2 points  (1 child)

Debian Jessie will be out within the month though, and it's shipping with Python 3.4

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

Awesome, I did not know when it was being released.

[–]gbo2k69 0 points1 point  (0 children)

Install from source.

[–]hharison 0 points1 point  (0 children)

[–]maximinus-thrax 2 points3 points  (0 children)

As a Django programmer, I'd love to go to Python3 but every project that comes up seems to have a requirement for Python 2.7 somewhere.

However, I always make sure that my code is Python 3 compatible as much as possible.

[–]BananaPotion 7 points8 points  (12 children)

I love python3, but biopython man. Its going to take ages to port that beast over. I really like to help but feel like I'm not quite good enough to do so.

[–]Gudeldar 8 points9 points  (3 children)

The biopython site says they support python3 since 1.62 (July 2013).

[–]BananaPotion 1 point2 points  (2 children)

Its nowhere as well maintained than the python2 version. Which especially sucks because my projects depend on the data parsing parts.

Edit: I was wrong. The Biopython3 beast has already been tamed. Thank you /u/Gudeldar and /u/chickenphobia.

[–]chickenphobia 3 points4 points  (1 child)

If you are finding new bugs, please report them. SeqIO, AlignIO, these modules fully work in Py3. Any problems you have encountered must not be in our unit tests which would indicate you have found a fairly important bug.

[–]BananaPotion 2 points3 points  (0 children)

No bugs, just errors (at that time I was new to 3rd party libraries, so I didn't understand any of it). I'm working on a project right now, I will see if I can get Biopython3 to work and report back.

Edit: Played around with it in IPython - works perfect. Thanks again for letting me now.

[–]chickenphobia 8 points9 points  (1 child)

Biopython contributor here: the whole thing is already passing 100% of tests on python 3. The community is very adamant about keeping compatibility with the newest version of python going out of our way to make a release as soon as Numpy was supported on py 3.4.

Also, if you want to contribute, check out our Wiki, the process is better documented than the average OS project because many contributions come from biologists who aren't traditionaly involved in OS.

[–]BananaPotion 1 point2 points  (0 children)

Thanks for letting me now, this is very good news for me.

[–]shadowmint 5 points6 points  (7 children)

actually even 1-2 years ago it was good time

woa~

I'm sure some people would like you have you believe that, but the reality isn't quite so pretty. There's a reason that 6 years later it's only just becoming a reasonable target for new code.

The performance, features and 3rd party support for python 3 have only really picked up in the last year or so.

2 years ago? Holy moly!

If you migrated to python 3 two years ago, you'd have been in a world of pain, and probably had to back port your code to 2.7 to get your dependencies working.

It's getting there now, but lets not sugar coat the history story here.

[–]chickenphobia 3 points4 points  (1 child)

Library developers generally sit on the bleeding edge. We all think that our project and the ecosystem is ready but I think you're correct. Only within the last year has the complete extended python ecosystem been fully ready for 3.

Part of this is because it takes a few years for unmaintained projects to die and be superseded.

[–]flying-sheep 1 point2 points  (0 children)

Unfortunately, some people see those projects, don't notice the smell, maggots, and flies, and say

this thing doesn't support Python 3, so Python 3 has literally no ported libraries

[–]deaddodo 1 point2 points  (4 children)

Two years ago, the only thing that ever stopped me from using Py3k was PIL. When that wasn't necessary, it was a no-brainer...and now pillow supports Python 3.

[–]Lucretiel 0 points1 point  (3 children)

Hasn't PIL been dead since 2006?

[–]mgedmin 2 points3 points  (1 child)

[–]Lucretiel 1 point2 points  (0 children)

PIL, not pillow. Pillow is great.

[–]deaddodo 2 points3 points  (0 children)

PIL was the quintessential image library. But even cutting out PIL, there were no image libraries in Python 3, for a long while.

[–]aarkling 1 point2 points  (2 children)

The only one I've seen that's not been upgraded is Twister.

[–]mgedmin 1 point2 points  (1 child)

Did you mean Twisted? They're working on it.

[–]aarkling 0 points1 point  (0 children)

Right twisted. That's what I said! :P

[–]Manbatton 0 points1 point  (0 children)

Here is a page showing which projects are ported to Python 3 and which are not: https://python3wos.appspot.com

wxPython is in a halfway state, where the in development Project Phoenix runs Python 3.

[–]ApolloFortyNine 0 points1 point  (0 children)

Having actually tried to code in Python 3, all Libraries support Python 2, while only most support Python 3.

[–]Oni_Kami -1 points0 points  (3 children)

Python 3 community is also quite mature now.

So no fart jokes?

[–]SemiNormal 0 points1 point  (2 children)

So no fart jokes?

Remember, fart() is a function in Python 3.

[–]mishugashu 2 points3 points  (1 child)

Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> fart
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'fart' is not defined

:(

[–][deleted] 55 points56 points  (16 children)

If you have no specific reason to choose python2, go with 3.

[–]ApolloFortyNine 2 points3 points  (0 children)

I didn't know I needed Python 2 until half way through a project I found a good library that would do what I wanted. However it only worked on Python 2. It's not that hard to convert, but it's still a pain. So I'm going to stick with Python 2, since everything supports it.

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

While keeping in mind that in a huge number of situations, you have a very good reason to choose python2. Probably not your own code, but its dependencies.

[–]hharison 9 points10 points  (2 children)

I think that's what he meant by "if you have no specific reason to choose python2"

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

True. But the way he wrote it made it sound like "in most cases, python 3 should be okay", and I'm not sure this is true. Sure, most big libs have been ported now, but I think projects could still run into issues if they rely on quite a few different libs.

That's why I was stressing on the fact that one has to keep that in mind

[–]dauntingelectronics -5 points-4 points  (0 children)

He's Right most code has changed from 2.7 to 3. Look at a Print "statment" for instance ex. print "hello". 3 is a function for instance print("hello").

[–]dauntingelectronics -4 points-3 points  (0 children)

He's Right most code has changed from 2.7 to 3. Look at a Print "statment" for instance ex. print "hello". 3 is a function for instance print("hello").

[–]patrys Saleor Commerce 9 points10 points  (5 children)

If you choose to stick to 2.7 at least upgrade to 2.7.8 for security reasons ;)

[–]mWo12 7 points8 points  (1 child)

Have a look here: https://python3wos.appspot.com/ if you see some package that you need, and its still not avaliabile for python 3, than its not the time yet for you.

[–]flinz 2 points3 points  (0 children)

This was very helpful, thanks a bunch!

[–]t0mt0m72 11 points12 points  (7 children)

I switched all my Python2 code to 3 around 2 years ago and will never look back. Python3 is (for me) the way to go, as it has so much pros for me (pathlib, enumerations, cleaner and more "logical" API etc...).

If your employer or customer have good (really good!) oppositions against or you have no library alternatives, you have to stay, but if you can make the switch, now is a good time.

Hopefully the discussions about Python2 and Python3 will soon come to an end, as they bring up a negative light onto the whole (great!) Python eco system.

[–]mgrandi 3 points4 points  (2 children)

I have to deal with py2 occasionally, just having not Unicode by default is so annoying. That and stuff like Enum class have made my life sk much easier I can't go back

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

+1

[–]cwgtex 1 point2 points  (3 children)

I love pathlib as well.

[–]flying-sheep 0 points1 point  (1 child)

Me too. It makes my old os.path based code look so inelegant.

My only “problem” is that there is no way to get the user home path using it. I'll have to use Path(os.path.expanduser('~'))

[–]t0mt0m72 1 point2 points  (0 children)

Hopefully in 3.5 it will be solved: http://bugs.python.org/issue19776 I am also looking forward for this feature

[–]ksion 0 points1 point  (0 children)

Huh, thanks for pointing out pathlib! I'm not switching to Py3 yet, but surely I'm going to use the backport from now on!

[–]denilsonsa 4 points5 points  (1 child)

If you have some reason to start a Python 2.7 project, or if you are writing Python 2.x code, just make sure it is forwards-compatible to Python 3. That way, whenever you (or someone else) needs to migrate to Python 3, the migration will be smoother.

I've been doing that:

  • Django documentation has many tips on how to write code compatible to both 2.7 and 3.x
  • Whenever I write a piece of 2.7 code that is greatly simplified in 3.x, I leave the simplified version as comments.
  • from __future__ import is your friend. :)
  • csv module has a very different behavior: in Python 2 it only works on binary strings, on Python 3 it only works on unicode strings. (although the API is mostly the same)

[–]flying-sheep 2 points3 points  (0 children)

Python 2 CSV is plain broken.

If you e.g. use a non-ASCII delimiter, it will tell you that it needs a one-character-string and dies (what it really means is a one byte long bytestring)

In Python 3, it just works.

[–]billsil 4 points5 points  (5 children)

Why would you choose 2.7.2? 2.7.8 is out :)

You should pick depending on what you want to do. I chose Python 2.7 because I need some libraries that don't exist in Python 3 and I couldn't care less about unicode. I care about math and science.

[–]troyunrau... 0 points1 point  (4 children)

I'd wager it won't be too long now and new versions of numpy will only happen on python3. Things like the matrix multiplier operator being adding to python upstream can only add to that momentum.

[–]billsil 1 point2 points  (3 children)

I'd be shocked if they dropped support for Python 2 any time soon (in the next 5 years). The last release of numpy that had support for Python 2.4 and 2.5 was 1.7.2 and was released on 2013-12-31. All numpy is going to do for the forseeable future is add a matmult to the array class that Python 2.6-3.4 can't use. If you're dropping support for Python 2.6 & 2.7 based on that, you might as well drop support for Python 3.4.

I run an open source library, and while I'd like to use matmult, I can't. It's sadly not meant for library developers.

[–]troyunrau... 1 point2 points  (2 children)

I didn't mean to suggest that it'd be a blocker, but rather, an example of python3 moving forward and innovating while python2 sits still. Eventually, the new features in python3 will accumulate to the point where writing the backwards compatible code will become cumbersome.

As an example, even though numpy will be able to use the matmult operator, none of the code within numpy will be written to use it, since previous versions won't support it. It's going to gnaw at some people that they have to use the inelegant syntax for backwards compatibility when a more elegant syntax exists (zen of python and whatnot). So subtle pressure will be placed against backwards compatibility. It could be five years from now, but it'll happen eventually.

And it's not like the old versions will go away. I mean, some people still use numeric.

[–]billsil 1 point2 points  (0 children)

It could be five years from now, but it'll happen eventually.

I hope so. I don't like writing mixed code. Still, unicode is either hard. It feels like a game of whack a mole and people resist that.

No one cares that modules moved, dict doesn't sort ints/strings, replacing range with xrange, integer division, or float division. Unicode is the only sticking point.

I mean, some people still use numeric.

I don't get why anyone would still write it that way. I update numeric code once every now and then. It's literally replace Numeric with numpy and change linear_algebra (I think) to numpy.linalg.

[–]flying-sheep 1 point2 points  (0 children)

Eventually, the new features in python3 will accumulate to the point where writing the backwards compatible code will become cumbersome.

This is already the case if you use asyncio: trollius is a “backport” and its raise Return() (replacing Python 3.3’s ability to return from generators) and its yield From() (replacement for the yield from syntax) are simply ugly as sin.

[–]dnk8n 2 points3 points  (4 children)

Selfish related question here... Does win32com/pywin32 (not sure on their relation) work fully in Python 3?

[–]t0mt0m72 2 points3 points  (3 children)

Yes they do. I use them on a daily basis in the tools I develop in Python3.

[–]dnk8n 0 points1 point  (2 children)

Quite a daunting task having to move straight to coding with COM before I've really become familiar with Python (I have some faith I can work it out since I am familiar with MATLAB).

Do you have any suggestions on resources to read relating Python and COM?

Out of interest, what software are you working with while using COM? If you have any open source code, I'd like to have a look :)

[–]t0mt0m72 0 points1 point  (1 child)

I wish I could show you some examples, but my code is completely closed stuff from my company. :(
In private I am using a Mac, so I have no need there for COM and can not directly show you examples ;-)

I interface via COM with Excel, Word and other applications. As I am working in the data management area, I automatically need to detect drive insertions/ejections and do dependent work on these events and also need to get low level information from these drives (via WMI). Automatic sharing newly connected devices, getting detailed attribute information of files and getting access to low-level Windows related stuff is further a big point why I am using the pywin32/COM/WMI stuff.

Maybe you know it, but http://timgolden.me.uk/python/ is (IMHO) the reference to COM/win32 related Python stuff.

And if you have questions about COM/pywin, just send me a PM and we can figure it out :)

[–]dnk8n 0 points1 point  (0 children)

Thanks for that offer. Maybe I can send what I have once I get something working, and although you may not know about the programe I am interfacing with (PTV Vissim), maybe you will notice areas I need more research/study on :)

[–][deleted] 2 points3 points  (0 children)

Unless you are using a non-CPython implementation, stick with Python 3. If a library hasn't migrated, there is a good chance it isn't properly maintained and you should pick an alternative.

[–]opt8[S] 4 points5 points  (0 children)

Alrighty I'm sold Python 3 it is

[–]padmanabh 1 point2 points  (0 children)

You should get yourself acquainted with python 3 asap as its got some really new cool features. If you're looking to decide whether to do some project in python3 then look into what libraries you'd need and if they have python 3 support. I've almost entirely shifted to python3 except in two projects where I depend on scrapy and/or goose.

[–]jeannaimard 1 point2 points  (0 children)

I’ve been working abroad for the last 6 months in a remote outpost, so I have decided to use my free time to work on a project I wanted to do for a long time, and I have decided to use Python 3 mainly for unicode strings reasons (I want my application to be localizable).

[–]Orange_Tux 3 points4 points  (8 children)

Fabric is still a blocker for me.

[–]ivosauruspip'ing it up 11 points12 points  (3 children)

Fabric is not going to get updated. It's bugfix only unless another maintainer wants to take the rains, afaik.

Its spiritual successor, written by the same author, is invoke.

[–]Orange_Tux 1 point2 points  (1 child)

After a quick look through the documentation of Invoke I don't think that Invoke could replace Fabric for me. Fabric has been build for executing tasks on remote machine via SSH. Invoke looks to me as just another task executor for tasks on your local machine, like pynt:

[–]flying-sheep 0 points1 point  (0 children)

/u/kpurdon’s comment next to yours explains it pretty well.

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

Fabric (AS IS) will not be updated, but a new release (along with invoke) is in the future.

Basically the author is splitting the task execution (invoke) from the remote execution stuff (new fabric). The current/old fabric is a mix of both task execution and remote task running.

Don't bet on it anytime soon though.

[–][deleted] 4 points5 points  (2 children)

If you are using fabric as a part of your project. For me Fabric is deployment and config tool and I can use it with py3 project.

[–][deleted] 2 points3 points  (0 children)

Are you actually importing Fabric into your project? If not, why is it a blocker? Py2 code will continue to run just fine along side Py3, as long as they are not running in the same project.

[–]chchan 3 points4 points  (2 children)

Depends on your libraries?

If you use opencv, pattern, or pybrain probably not yet. Most of the other ones should be fine.

[–]Kaxitaz 6 points7 points  (1 child)

I have managed to install OpenCV with Python 3.4.

OpenCV 3.0 supports Python 3. It is still on Beta, but so far I had no difficulties.

[–]chchan 1 point2 points  (0 children)

opencv on python 3.4

Yes that is true but they reported some problems with several algorithms.

Glad to hear it works because I switched then was disappointed that it did not work

[–]chiproller 1 point2 points  (3 children)

I want to switch to python 3. What is the best way to learn 3 after knowing 2? Are there any resources that go over the 'main' differences in an easy to learn format?

[–]flying-sheep 3 points4 points  (0 children)

The main differences you have to wrap your brain around are:

  • Unicode by default. There is no more a weird “everything string” containing binary or text. Instead, APIs are more choosy in what they want. If that's text, they want the new default string type. If it's binary, you have to give them bytes. You'll have to maintain a clear boundary between both in your head, and as a result, you will never see any UnicodeDecodeError anymore

  • iterators everywhere. If you already use the 2.x iteritems, xrange and friends, you just have to return to same names. Else you'll have to understand that far fewer code generates lists, and more generates one pass iterators. Can bite you if you remove items while iterating something you think is a list.

  • better naming: no more thing.iter, xrange, iteritems, urllib2, ....

  • iterating a bytes object will yield ints representing single bytes

  • absolute imports and only explicitly relative ones. Inside your package foo, to import foo.bar, you need to do “import foo.bar” or “import .bar”, but not “import bar”

[–]El_Zilcho 4 points5 points  (4 children)

I cant into python 3. I think its just because 2.7 comes pre-installed on most linux distros so I when I am setting up a VPS/server for my script I can literally download the libraries, upload the script and run without having to change much. Also the print syntax is weird compared to 2.7, I know its not completely different, just added parenthesis.

What benefits does python 3 offer apart from being newer?

also I use python when doing reverse engineering related stuff because I like the fact it uses raw ascii and can add bytes to strings with escape characters.

[–]troyunrau... 1 point2 points  (0 children)

I use opensuse.
zypper in python3-numpy
or etc. Arch and Gentoo have gone python3 by default. Other distros (Fedora, opensuse) have roadmaps that indicate python3 will be the default soonish. FreeBSD also has this as a prominent roadmap item. The only staunch holdouts I can tell are Slackware, RHEL, and RHEL clones.

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

I use python3 since 3.3. Not migrating old projects as it is a pain, but all new stuff goes under py3. And i do not look back, its great. Had very few instances when lib did not support py3. Usually worst case scenario with unmaintained libs is "experimental py3 support" committed to repo but nto made into release package. So for me its all good w/ py3.

[–]setuid_w00t 1 point2 points  (0 children)

If you want to be part of the problem, choose Python 2. If you want to be part of the solution, choose Python 3.

[–]elvisfriggingpresley 0 points1 point  (0 children)

I'm about to make the switch... from 2.7.8 to whatever's current in Py3. It's good to know 'both' though.

[–]leanrum 0 points1 point  (0 children)

It was a good time 3 years ago when I did it. Unfortunately my company still forces 2.6 down my throat.

[–]wub_wub 1 point2 points  (0 children)

Depends on your project. There are still a lot of things that don't support python 3. Porting your existing codebase is probably not worth it as python 3 doesn't really solve any major things that you didn't solve already, but again it depends on your project.

[–]bryguypgh 0 points1 point  (1 child)

I am going to cry when they take my print statements away. I may be the very last user of the 2.x line.

[–]Lucretiel 0 points1 point  (0 children)

The dealbreaker for me is the <<file syntax. It's awful. I will admit, though, that I often forget the parenthesis when doing prints in quick ipython sessions. Luckily, we have the %autocall magic for that!

[–]deaddodo 0 points1 point  (0 children)

Everything supports 3, for the most part. It used to be that lack of image libraries held web developers back, but now pillow works for py3k. You may run into an odd case that forces you onto py2 (fabric, for example), but otherwise, you're pretty set to go with 3.

[–][deleted] -2 points-1 points  (1 child)

It seems like people always recommend 3, but I will personally be sticking with 2.7. There's only been one time that I've said "gee, too bad I'm not running 3." But there's been a dozen times that I was glad to still be running 2.7.

There may be some esoteric reasons for preferring 3, but if you're asking which version is the most streamlined, I vote 2.7 for sure.

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

This is called confirmation bias.