0

I've seen other answers for this on Stack, but they aren't helping.

I have a Python 2.7 script that I need converted to work with Python 3. It seems like using 2to3 shouldn't be this difficult, but I can't figure it out. In the Windows command line, I try typing "python C:\Python27\Tools\Scripts\2to3.py (path to my file)" and it says "Invalid syntax" and has a little carrot pointing to the C in the first file path.

I also try opening the IDLE shell and typing "$ 2to3 (path to my script)", which also says "Invalid syntax" and highlights the $. So I get rid of the $ and try again, and then it highlights the "2to3" with Invalid Syntax.

I've seen other answers as well, and none come even close to working. I feel like an idiot for not getting this. What am I missing? Can someone explain it like I'm five?

(I'm fairly new to programming, but I've been doing pretty well writing scripts in Python. I have no idea why THIS is the thing I'm struggling with.)

Nathan R
  • 840
  • 5
  • 13
  • 32
  • Is "(path to my file)" something else than you show here? Does it contain spaces? – Jongware May 01 '16 at 01:39
  • Sorry, what I mean there is "C:\Python27\myfile.py" . So what I type in the cmd is "python C:\Python27\Tools\Scripts\2to3.py C:\Python27\myfile.py". In the IDLE shell it's "$ 2to3 C:\Python27\myfile.py" – Nathan R May 01 '16 at 01:42
  • 2
    Could you copy and paste the entire error message? That's exactly the error you'd get if you *didn't* run that command at the windows command line but you ran it in the Python console.. – DSM May 01 '16 at 01:44
  • Thanks DSM, that got me thinking... I had typed "Python" and hit enter BEFORE typing "Python C:\BlahBlah etc...", so I guess the cmd was already in Python mode or something. I tried it without typing Python by itself first and it worked! Still don't know why it's not working on the IDLE shell though. – Nathan R May 01 '16 at 01:49

1 Answers1

2

Does this work for you?

python C:\Python27\Tools\scripts\2to3.py -w <your_file>.py

This will make the necessary changes to make you <your_file>.py to make it compatible with python3 and overwrite the original file

See 2to3 documentation

Tasdik Rahman
  • 2,160
  • 1
  • 25
  • 37