tensorflow icon indicating copy to clipboard operation
tensorflow copied to clipboard

Add support for Python 3.x

Open mrry opened this issue 11 years ago • 48 comments

Currently we only support Python 2.7, but we should support Python 3.

mrry avatar Nov 09 '15 14:11 mrry

Main things this involves: print -> print(), handle __floordiv__ / __truediv__ / __div__ correctly.

girving avatar Nov 09 '15 14:11 girving

:+1: to this issue

cdnsteve avatar Nov 09 '15 15:11 cdnsteve

:+1:

dvbuntu avatar Nov 09 '15 15:11 dvbuntu

:+1:

ashwin31 avatar Nov 09 '15 16:11 ashwin31

:+1:

joestepp avatar Nov 09 '15 17:11 joestepp

We're working on it.

girving avatar Nov 09 '15 17:11 girving

Python 3 is a must have. :+1:

kevinaloys avatar Nov 09 '15 21:11 kevinaloys

How do we contribute towards python3 support? Are there any specific tickets open? Is there a python3 development branch?

mgcdanny avatar Nov 09 '15 22:11 mgcdanny

@mgcdanny seems they require contributors to sign an agreement first. https://github.com/tensorflow/tensorflow/blob/master/CONTRIBUTING.md

cdnsteve avatar Nov 09 '15 22:11 cdnsteve

:+1:

MikalaiDrabovich avatar Nov 09 '15 23:11 MikalaiDrabovich

I'm running futurize on the code at the moment; once that's done it'll be easier to parallelize the remaining work. So far futurize --stage1 is checked in and I'm working through futurize --stage2 now (checking each of our divisions very carefully :)).

Unfortunately our contribution process needs a bit of improvement (we're working on streamlining it), but I'll see if there are natural chunks of work to break off and ask for help in fixing once the initial futurize push is done. Before that it's tricky to parallelize.

The only non-obvious questions (so far) are what to do with unicode and where. Cc'ing @mrry since he was taking a look at that. Most of the "names" for things, such as names for ops and names for tensors in a graph, are already restricted to be roughly alphanumeric, so hopefully we should be able to leave them as C++ string while still accepting unicode input from Python.

girving avatar Nov 10 '15 00:11 girving

Also, question for people that have done such conversions before / recently: is six still the recommended way to make code transparently support both? In particular, we need stuff like xrange and iteritems as symbols that exist in both 2.7 and 3.x.

girving avatar Nov 10 '15 00:11 girving

@girving I would follow the guide written by python3 core dev Brett Cannon: https://docs.python.org/3.5/howto/pyporting.html. He's been heavily involved with the push to move existing libs to python3.

madisonmay avatar Nov 10 '15 00:11 madisonmay

@madisonmay: Thanks, should have asked you earlier. Modernize probably would have been a better choice, since after reading that page I am essentially taking the output of futurize and then rewriting it into what modernize might have already spit out. Mostly done with that phase, though, so I'll probably just finish it up using futurize.

For the record: futurize --stage was mostly print_function and a few other safe trivialities. I'll write a detailed comment on what futurize --stage2 involved for us once I'm done with it (still in the middle of reading diffs).

girving avatar Nov 10 '15 00:11 girving

+1

yuncliu avatar Nov 10 '15 09:11 yuncliu

I think it is pretty clear that there are many people interested in this issue. However, I would suggest users to use the Subscribe button instead of adding a new :+1:.

screenshot from 2015-11-10 10-36-53

This way developers (and all subscribed users) can get notifications on useful future updates. :wink:

PS: If you already posted a :+1: you might as well consider removing it to keep the discussion cleaner.

Peque avatar Nov 10 '15 09:11 Peque

Thank you @Peque! It would be great if further comments were limited to technical discussions about Python 3 support.

girving avatar Nov 10 '15 17:11 girving

From the README:

The TensorFlow Python API currently requires Python 2.7: we are working on adding support for Python 3.0.

If you require 2.7 for the 2.X line, then why restrict yourselves to 3.0 (which was released about the time of 2.6)? If you target 3.3+, then you'll save yourselves a lot of headache, especially if you're using u'あ' unicode strings. (also see unicode_literals).

And :+1: for six for more complicated things.

goodmami avatar Nov 11 '15 22:11 goodmami

Sorry, I meant Python 3, not 3.0 -- was in a rush to fix :P. I'll fix this today

vrv avatar Nov 11 '15 22:11 vrv

@goodmami: Yes, we will likely only support 3.3+, possibly 3.4+ (I'm not sure what the differences are, but will look that up). I also changed the issue title.

girving avatar Nov 11 '15 22:11 girving