Python Forum
Migration of Python2 and Python3 using Modernize and Future
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Migration of Python2 and Python3 using Modernize and Future
#1
I am working on the migration of files from Python2.7 to Python3+. As a part of preparation, I have come across utility 2to3, Modernize and Futurize

2To3 seems to be very simple and I have managed to try out examples. Since it is not backward compatible, it is suggested that Modernize and Futurize are better

I installed the modernize library and Six as well, I have 2 versions of Python on my system (2.7 and 3.9)
I have a sample(Test.py) python2 code.

def greet(name):
    print "Hello, {0}!, How are you doing?" .format(name)
print "Your name?"
name = raw_input()
greet(name)
Now I go to the directory to run the command :
python-modernize -w Test.py
I observe that the python file is migrated to python3. When I run the code with the python3 interpreter from the command line, it works as expected.

New Test.py:
from __future__ import print_function
from six.moves import input
def greet(name):
    print("Hello, {0}!, How are you doing?" .format(name))
print("Your name?")
name = input()
greet(name)
However, since it promises backward compatibility, I expect it to run with Python2 interpreter as well
When I do the following :
C:\Python27\python.exe Test.py
I get an error:
Error:
Traceback (most recent call last): File "Test.py", line 2, in <module> from six.moves import input ImportError: No module named six.moves
I uninstalled and installed the six library, but no success. What am I doing wrong here?
Reply


Messages In This Thread
Migration of Python2 and Python3 using Modernize and Future - by Rakshan - Feb-21-2022, 12:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 487 Mar-07-2024, 03:40 PM
Last Post: deanhystad
Sad Migrating of python2 script to python3 zuri 7 1,082 Oct-05-2023, 02:40 PM
Last Post: snippsat
  PyPi Download Counts and Warehouse Migration? tlee0818 1 1,330 Mar-20-2022, 07:41 PM
Last Post: snippsat
  db migration(db version control) for python lubaz 2 2,829 May-30-2021, 01:36 PM
Last Post: lubaz
  python2 python3 messed up : How to fix ? hary 15 8,185 Dec-30-2020, 08:26 PM
Last Post: hary
  Getting a small Python2 prog to run in Python3 steve140 4 3,955 Apr-19-2020, 09:27 AM
Last Post: steve140
  output mismatching when porting a python from python2 env to python3 env prayuktibid 2 2,626 Jan-21-2020, 04:41 AM
Last Post: prayuktibid
  python3 decoding problem but python2 OK mesbah 0 1,831 Nov-30-2019, 04:42 PM
Last Post: mesbah
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,988 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  Trying to run a python2 script dagamer1991 3 2,581 Aug-12-2019, 12:33 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020