Python 2to3 windows CMD

Question:

I have installed python 32 package to the

C:python32

I have also set the paths:

PYTHONPATH | C:Python32Lib;C:Python32DLLs;C:Python32Liblib-tk;

PATH ;C:Python32;

I would like to use the “2to3” tool, but CMD does not recognize it.

CMD: c:testpython> 2to3 test.py

Should i add an extra path for “2to3” or something?

Thanks

Asked By: John

||

Answers:

2to3 is actually a Python script found in the Tools/scripts folder of your Python install.

So you should run it like this:

python.exe C:Python32Toolsscripts2to3.py your-script-here.py

See this for more details: http://docs.python.org/library/2to3.html

Answered By: oblio

You can set up 2to3.py to run as a command when you type 2to3 by creating a batch file in the same directory as your python.exe file (assuming that directory is already on your windows path – it doesn’t have to be this directory it just is a convenient, relatively logical spot).

Lets assume you have python installed in C:Python33. If you aren’t sure where your python installation is, you can find out where Windows thinks it is by typing where python from the command line.

You should have python.exe in C:Python33 and 2to3.py in C:Python33ToolsScripts.

Create a batch file called 2to3.bat in C:Python33Scripts and put this line in the batch file

@python "%~dp0..ToolsScripts2to3.py" %*

The %~dp0 is the location of the batch file, in this case c:Python33Scripts and the %* passes all arguments from the command line to the 2to3.py script. After you’ve saved the .bat file, you should be able to type 2to3 from the command line and see

At least one file or directory argument required.
Use --help to show usage.

I have found this technique useful when installing from setup.py, because sometimes the setup script expects 2to3 to be available as a command.

Answered By: monknomo

Make a batch file then rename it to 2to3.bat and paste this code in it:

@python "%~dp0ToolsScripts2to3.py" %*

Copy that file beside your python.exe file, for me that folder is:
C:UsersAdminAppDataLocalProgramsPythonPython38

Usage:

2to3 mycode.py
Answered By: team meryb
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.