How to use Python 2to3 Converter with Pycharm IDE

Valliappan Thenappan
2 min readDec 22, 2020

As a Python developer, we would be dealing with a lot of old python 2.x code which we would like to convert it to Python 3. Python by default provides us a nice command line utility called 2to3. You can read more about it here.

But let us say we want to use Pycharm to do that for us. All we need is few configurations using Pycharm’s External tools.

Here are the steps:

(1) First step is to find where the 2to3 utility is located in your system, o find that we can use the ‘which’ command as follows:

Open a terminal (For windows and linux) and type which 2to3 , this should give you the path of it. For me it was located on /usr/local/bin/2to3

(2) Open Pycharm->Preferences->Tools->External Tools and add a new tool with the following options:

Note the -w option, this means once you run this on a file, the changes get written to the disk.

(3) Now for the usage, take any python file which is in version 2.x and right click on the file and choose External Tools->2to3

Voila, this should convert your file to Python 3 as follows:

You can do this conversion on a directory level as well which will apply changes to all files within the directory. Hope you enjoyed the short read. Cheers!

--

--