Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use/install python 2to3?

Tags:

From this https://docs.python.org/3.4/library/2to3.html it says that 2to3 should be installed as a script alongside the python interpreter. However, in my /usr/bin/ folder there are no 2to3 executable, and running find from / finds no 2to3 executable either. I do however have a folder called lib2to3 at /usr/lib64/python{3.4/2.7}/lib2to3 but containing nothing I found relevant. In python/site-packages/setuptools/ there is a lib2to3_ex.py script, but nothing happens if I run it. How do I get to the point where I can simply type 2to3 upgradethisscripttopython3.py ?

like image 593
Kirbies Avatar asked Jul 05 '15 09:07

Kirbies


People also ask

How do I use Python 2to3?

To convert a certain python 2 code to python 3, go to your command promt, change the directory to C:/Program Files/Python36/Tools/scripts where the 2to3 file is found. Then add the following command: python 2to3.py -w (directory to your script).


2 Answers

You need to first install the following packages:

apt install 2to3
apt install python3-lib2to3
apt install python3-toolz

For windows just install 2to3

pip install 2to3

Then, You can simply go to that directory your python file is in and type the following command:

2to3 ./filename.py

OR for writing the updated python 3 code to the existing file

2to3 . -w

This last will convert all the python files that are in the directory.

like image 101
Daniyal Naeem Avatar answered Oct 19 '22 01:10

Daniyal Naeem


So the solution is that at least not for me, the Tools/scripts files were not automatically installed. On ubuntu this would be solved by installing python-examples which on opensuse is called python-demo

like image 30
Kirbies Avatar answered Oct 19 '22 02:10

Kirbies