DEV Community

Rohit Nishad
Rohit Nishad

Posted on

18 3

Convert python 2 to python 3 [In 1 Single Click]

After 1 January 2020 many companies and individuals are worried about their Python 2 code because Python’s organization stops support for Python 2, and the new development era was moving to python3 to solve this problem. There. They are few packages developed over time, one of them is official and extremely powerful.

Three Library that is used to convert your Python 2 code to Python 3 code.

  1. 2to3 (Offical, recommended)
  2. Python Future + Futurize
  3. Six + Modernize

Now at this point, you definitely thinking well, what’s the difference between, 2to3, Python Future + Futurize, and Six + Modernize.

Here’s your answer!

What’s the difference between

Automated tools for PY2 to PY3 conversion/compatibility?

2to3, Python Future + Futurize, and Six + Modernize

How to convert Python 2 to Python 3

This can be very easy if you use any of the above libraries (do not forget to make sure the compatibility)
There are two approaches for converting Python 2 to python 3.

Method #1: Convert Python 2 to python 3 using web-tool.

There is a simple tool for converting python 2 to python 3.

you can use a web application to convert python 2 to 3.

This tool is:

  1. 100% FREE
  2. Compatible with All versions of Python
  3. Actively maintained

Method #2: Convert Python 2 to python 3 using a python library.

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

Step 1: Open your terminal and navigate to your File

Open your terminal or CMD depend on whatever you are using Windows or Linux.

Navigate to the directory where your python file(s) is/are located. (of course, using the “cd” command)

Step 2: Install the library

As usable, use pip to install 2to3, use can use any other library as well, I like 2to3

Commnd: pip install 2to3

Step 3: Convert the files

Excute: 2to3 [file or folder] -w

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
pragyansatapathy profile image
Pragyan Satapathy
Comment hidden by post author

Some comments have been hidden by the post's author - find out more

Neon image

Set up a Neon project in seconds and connect from a Python application

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay