How to use 2to3 properly for python?

GhostFrag1 picture GhostFrag1 · Dec 8, 2013 · Viewed 52.4k times · Source

I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.

Answer

Faruk Sahin picture Faruk Sahin · Dec 8, 2013

Install the following module which adds the 2to3 command directly to entry_points.

pip install 2to3

As it is written on 2to3 docs, to translate an entire project from one directory tree to another, use:

2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode