2to3 Help?

Discussion in 'Python' started by marco.m.petersen@gmail.com, Jan 15, 2009.

  1. Guest

    I have Python 3.0. I tried to use the 2to3 program included with the
    interpreter to convert some scripts for Python 2.5 to Python 3.0 ones.
    When I try to start it form the Python command line, it says it is a
    syntax error.

    This was the line of code:

    $ 2to3 testscript.py

    Any help would be appreciated.

    Thanks
    - Marco
     
    , Jan 15, 2009
    #1
    1. Advertising

  2. James Mills Guest

    On Thu, Jan 15, 2009 at 4:01 PM, <> wrote:
    > I have Python 3.0. I tried to use the 2to3 program included with the
    > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones.
    > When I try to start it form the Python command line, it says it is a
    > syntax error.
    >
    > This was the line of code:
    >
    > $ 2to3 testscript.py
    >
    > Any help would be appreciated.


    $ 2to3 testscript.py
    RefactoringTool: Skipping implicit fixer: buffer
    RefactoringTool: Skipping implicit fixer: idioms
    RefactoringTool: Skipping implicit fixer: set_literal
    RefactoringTool: Skipping implicit fixer: ws_comma
    RefactoringTool: Can't open testscript.py: [Errno 2] No such file or
    directory: 'testscript.py'
    RefactoringTool: No files need to be modified.
    RefactoringTool: There was 1 error:
    RefactoringTool: Can't open testscript.py: [Errno 2] No such file or
    directory: 'testscript.py'

    Seems to work perfectly fine here.

    It would greatly help if you showed us the error!

    cheers
    James
     
    James Mills, Jan 15, 2009
    #2
    1. Advertising

  3. Guest

    On Jan 15, 2:09 pm, "James Mills" <>
    wrote:
    > On Thu, Jan 15, 2009 at 4:01 PM,  <> wrote:
    > > I have Python 3.0. I tried to use the 2to3 program included with the
    > > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones.
    > > When I try to start it form the Python command line, it says it is a
    > > syntax error.

    >
    > > This was the line of code:

    >
    > > $ 2to3 testscript.py

    >
    > > Any help would be appreciated.

    >
    > $ 2to3 testscript.py
    > RefactoringTool: Skipping implicit fixer: buffer
    > RefactoringTool: Skipping implicit fixer: idioms
    > RefactoringTool: Skipping implicit fixer: set_literal
    > RefactoringTool: Skipping implicit fixer: ws_comma
    > RefactoringTool: Can't open testscript.py: [Errno 2] No such file or
    > directory: 'testscript.py'
    > RefactoringTool: No files need to be modified.
    > RefactoringTool: There was 1 error:
    > RefactoringTool: Can't open testscript.py: [Errno 2] No such file or
    > directory: 'testscript.py'
    >
    > Seems to work perfectly fine here.
    >
    > It would greatly help if you showed us the error!
    >
    > cheers
    > James


    The error was:

    >>> $ 2to3.py testscript.py

    File "<stdin>", line 1
    $ 2to3.py testscript.py
    ^
    Syntax Error: Invalid Syntax

    >>>
     
    , Jan 15, 2009
    #3
  4. James Mills Guest

    On Thu, Jan 15, 2009 at 4:17 PM, <> wrote:
    >>>> $ 2to3.py testscript.py

    > File "<stdin>", line 1
    > $ 2to3.py testscript.py
    > ^
    > Syntax Error: Invalid Syntax


    Oh i see...

    You need to do 2 things:

    1) Run 2to3 on the shell not the python interpreter.
    2) Learn some basic UNIX.

    cheers
    James
     
    James Mills, Jan 15, 2009
    #4
  5. Guest

    > You need to do 2 things:
    >
    > 1) Run 2to3 on the shell not the python interpreter.
    > 2) Learn some basic UNIX.
    >
    > cheers
    > James


    I tried to run it on the command prompt (I use Windows XP) but it
    doesn't work either.

    I opened the command prompt:

    C:\Documents and Settings\User>

    Then I typed '$ 2to3 testscript.py':

    C:\Documents and Settings\User>$ 2to3.py testscript.py

    But then this appears:

    C:\Documents and Settings\User>$ 2to3.py testscript.py
    '$' is not recognized as an internal or external command,
    operable program or batch file.

    Anyway I'll try some UNIX. Thanks.
     
    , Jan 15, 2009
    #5
  6. James Mills Guest

    On Thu, Jan 15, 2009 at 4:32 PM, <> wrote:
    > I tried to run it on the command prompt (I use Windows XP) but it
    > doesn't work either.


    I did not realize you were using WIndows :)
    Normally most shells in the UNIX/Linux world
    start with a '$'.

    > I opened the command prompt:
    >
    > C:\Documents and Settings\User>
    >
    > Then I typed '$ 2to3 testscript.py':
    >
    > C:\Documents and Settings\User>$ 2to3.py testscript.py
    >
    > But then this appears:
    >
    > C:\Documents and Settings\User>$ 2to3.py testscript.py
    > '$' is not recognized as an internal or external command,
    > operable program or batch file.


    Your problem is, you are treating the '$' (most likely
    copied/pasted from readings on the web) as part
    of what you need to enter into the command prompt.

    '$' is (like I said above) normally part of most commonly
    configured shells (eg: Bash).

    You need to just enter:

    2to3 testscript.py

    > Anyway I'll try some UNIX. Thanks.


    That is a good idea :) Windows teaches you nothing!

    cheers
    James
     
    James Mills, Jan 15, 2009
    #6
  7. alex23 Guest

    On Jan 15, 4:32 pm, wrote:
    > I tried to run it on the command prompt (I use Windows XP) but it
    > doesn't work either.
    > '$' is not recognized as an internal or external command,
    > operable program or batch file.


    '$' is used in the instructions to denote a command prompt. You're not
    supposed to type it :)

    In your case '$' == 'C:\Documents and Settings\User>'; just type
    '2to3.py testscript.py' and it should work (assuming it's location is
    in your PATH and you have the right handlers set up to launch it)
     
    alex23, Jan 15, 2009
    #7
  8. Guest

    Oh okay. I don't think my Python installation is in PATH yet. I'll try
    to add it then.
     
    , Jan 15, 2009
    #8
  9. alex23 Guest

    On Jan 15, 4:52 pm, wrote:
    > Oh okay. I don't think my Python installation is in PATH yet. I'll try
    > to add it then.


    I don't yet have 3.0 installed, but my guess is you'll also need to
    have 'C:\Python30\Scripts' in your path as well. I'm assuming that's
    where it resides, so check first.
     
    alex23, Jan 15, 2009
    #9
  10. Guest

    > I don't yet have 3.0 installed, but my guess is you'll also need to
    > have 'C:\Python30\Scripts' in your path as well. I'm assuming that's
    > where it resides, so check first.


    Its in C:\Python30\Tools\Scripts.

    Anyway it now works.

    C:\Documents and Settings\User>python C:\Python30\Tools\Scripts
    \2to3.py C:\Python30\testscript.py

    Thanks a lot alex23.
     
    , Jan 15, 2009
    #10
  11. John Machin Guest

    On Jan 15, 5:52 pm, wrote:
    > Oh okay. I don't think my Python installation is in PATH yet. I'll try
    > to add it then.


    Am I permitted to ask a really silly question?
    Thanks.
    Here it is: How much working 2.X code do you have that needs migrating
    from 2.x to 3.x?

    Cheers,
    John
     
    John Machin, Jan 15, 2009
    #11
  12. Terry Reedy Guest

    wrote:
    > I have Python 3.0. I tried to use the 2to3 program included with the
    > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones.


    I believe 2to3 is will work 'best' with files modified to use some new
    2.6 features (backported from 3.0) where 'best' means 'Runs with 2.6 and
    then with 3.0 after 2to3 conversion without hand editing'. If you want
    to do a one-time conversion, then 2.5 to 3.0 is fine.
     
    Terry Reedy, Jan 15, 2009
    #12
  13. jjh Guest

    On Jan 14, 10:01 pm, wrote:
    > I have Python 3.0. I tried to use the 2to3 program included with the
    > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones.
    > When I try to start it form the Python command line, it says it is a
    > syntax error.
    >
    > This was the line of code:
    >
    > $ 2to3 testscript.py
    >
    > Any help would be appreciated.
    >
    > Thanks
    > - Marco


    Sorry to bring this back up. I'm a newbie trying to run 2to3 on
    Windows. I ran the following:

    C:\Python30\python.exe C:\Python30\Tools\Scripts\2to3.py c:\python\src
    \testscript.py

    and I got the following:

    C:\Users\user>C:\Python30\python.exe C:\Python30\Tools\Scripts\2to3.py
    c:\python\src\testscript.py
    RefactoringTool: Skipping implicit fixer: buffer
    RefactoringTool: Skipping implicit fixer: idioms
    RefactoringTool: Skipping implicit fixer: set_literal
    RefactoringTool: Skipping implicit fixer: ws_comma
    --- c:\python\src\testscript.py (original)
    +++ c:\python\src\testscript.py (refactored)
    @@ -1,3 +1,3 @@
    #! /usr/bin/python

    -print "Hello World";
    +print("Hello World");
    RefactoringTool: Files that need to be modified:
    RefactoringTool: c:\python\src\testscript.py

    what am I suppose to do after that? I thought it would re-write my
    testscript.py but it didn't. Thanks so much for the help.
     
    jjh, Mar 5, 2009
    #13
  14. John Machin Guest

    On Mar 5, 6:47 pm, jjh <> wrote:
    > On Jan 14, 10:01 pm, wrote:

    [snipped]

    > Sorry to bring this back up.


    The correct thing to do is to start a NEW post. Marco's problem is
    nothing to do with yours.




    > I'm a newbie trying to run 2to3 on
    > Windows. I ran the following:
    >
    > C:\Python30\python.exe C:\Python30\Tools\Scripts\2to3.py c:\python\src\testscript.py


    The .exe should not be necessary ... if you have put a python.bat or a
    python.com or similar in that directory, lose them soon.

    >
    > and I got the following:
    >
    > C:\Users\user>C:\Python30\python.exe C:\Python30\Tools\Scripts\2to3.py
    > c:\python\src\testscript.py
    > RefactoringTool: Skipping implicit fixer: buffer
    > RefactoringTool: Skipping implicit fixer: idioms
    > RefactoringTool: Skipping implicit fixer: set_literal
    > RefactoringTool: Skipping implicit fixer: ws_comma
    > --- c:\python\src\testscript.py (original)
    > +++ c:\python\src\testscript.py (refactored)
    > @@ -1,3 +1,3 @@
    >  #! /usr/bin/python
    >
    > -print "Hello World";
    > +print("Hello World");
    > RefactoringTool: Files that need to be modified:
    > RefactoringTool: c:\python\src\testscript.py
    >
    > what am I suppose to do after that? I thought it would re-write my
    > testscript.py but it didn't. Thanks so much for the help.


    What made you think so? Thinking is a very good idea, but when you are
    a new user of a piece of software it's an even better idea to read the
    manual (http://docs.python.org/3.0/library/2to3.html) and check that
    it follows the usual command-line help convention (c:\python30\python
    c:\python30\tools\scripts\2to3.py --help) and that the fancy Windows
    help for Python is working ((Windows XP) click on Start>All
    Programs>Python 3.0>Python Manuals, type 2to3 then Enter) just in case
    you are ever disconnected from the Internet and/or want faster
    response.

    HTH,
    John
     
    John Machin, Mar 5, 2009
    #14
  15. Ant Guest

    On Jan 15, 6:43 am, "James Mills" <>
    wrote:
    ....
    > That is a good idea :) Windows teaches you nothing!


    Not true. Windows teaches you the art of the workaround...
     
    Ant, Mar 5, 2009
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robin Becker

    2to3.py download

    Robin Becker, Feb 12, 2008, in forum: Python
    Replies:
    0
    Views:
    670
    Robin Becker
    Feb 12, 2008
  2. Guilherme Polo

    Re: 2to3.py download

    Guilherme Polo, Feb 12, 2008, in forum: Python
    Replies:
    0
    Views:
    973
    Guilherme Polo
    Feb 12, 2008
  3. Helmut Jarausch

    2to3 bug and question

    Helmut Jarausch, Jun 23, 2008, in forum: Python
    Replies:
    2
    Views:
    255
    Terry Reedy
    Jun 23, 2008
  4. Helmut Jarausch

    [2to3] Bug converting import

    Helmut Jarausch, Jun 23, 2008, in forum: Python
    Replies:
    1
    Views:
    244
    Christian Heimes
    Jun 23, 2008
  5. Replies:
    4
    Views:
    471
    Isaac Gouy
    Jan 2, 2009
Loading...

Share This Page