Open In App
Related Articles

Automate the Conversion from Python2 to Python3

Improve Article
Save Article
Like Article

We can convert Python2 scripts to Python3 scripts by using 2to3 module. It changes Python2 syntax to Python3 syntax. We can change all the files in a particular folder from python2 to python3.


This module does not come built-in with Python. To install this type the below command in the terminal.

pip install 2to3


2to3 [file or folder] -w

If we want to change all files in the currently open folder and all the files in the subfolder from Python2 to Python3 type the below command.


If we want to change a particular file in the current folder from Python2 to Python3 then enter the following command.

2to3 -w

Example: Consider a simple Python2 file.


To convert this file from Python2 to Python3 open the terminal in the directory containing the file and type the below command.


The Python file will now be converted to Python3. Let’s see the file.


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 16 Jul, 2020
Like Article
Save Article
Similar Reads
Complete Tutorials