Search code examples
pythonpython-2to3

How to use 2to3 in Python Shell?


I want to import 2to3.py in the shell, but it keeps saying SyntaxError.

>>> site.addsitedir('/Python27/Tools/Scripts/')
>>> sys.path
['C:\\Senti\\ltpservice', 'C:\\Python27\\Lib\\idlelib', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\Tools\\Scripts']
>>> import 2to3
SyntaxError: invalid syntax

What should I do?


Solution

  • You're trying to import something starting with a number:

    >>> import 1sdjkhl
      File "<stdin>", line 1
        import 1sdjkhl
               ^
    SyntaxError: invalid syntax
    >>> 
    

    2to3 isn't a module, it's a tool. You run it like this in the shell:

    $ 2to3 myscript.py