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.
New Test.py:
When I do the following :
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.pyI 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.pyI 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?