Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 2to3 windows CMD

Tags:

python

I have installed python 32 package to the

C:\python32

I have also set the paths:

PYTHONPATH | C:\Python32\Lib;C:\Python32\DLLs;C:\Python32\Lib\lib-tk;

PATH ;C:\Python32;

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

CMD: c:\test\python> 2to3 test.py

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

Thanks

like image 246
John Avatar asked Apr 11 '12 11:04

John


People also ask

How do I run Python 2to3?

To convert a certain python 2 code to python 3, go to your command promt, change the directory to C:/Program Files/Python36/Tools/scripts where the 2to3 file is found. Then add the following command: python 2to3.py -w (directory to your script).

What is 2to3 in Python?

2to3 is a Python program that reads Python 2. x source code and applies a series of fixers to transform it into valid Python 3. x code. The standard library contains a rich set of fixers that will handle almost all code.


2 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:\Python32\Tools\scripts\2to3.py your-script-here.py

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

like image 199
2 revs Avatar answered Oct 21 '22 11:10

2 revs


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:\Python33\Tools\Scripts.

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

@python "%~dp0\..\Tools\Scripts\2to3.py" %*

The %~dp0 is the location of the batch file, in this case c:\Python33\Scripts 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.

like image 44
monknomo Avatar answered Oct 21 '22 10:10

monknomo