Python 2to3 windows CMD

前端 未结 3 537
臣服心动
臣服心动 2021-02-03 22:14

I have installed python 32 package to the

C:\\python32

I have also set the paths:

PYTHONPATH | C:\\Python32\

相关标签:
3条回答
  • 2021-02-03 22:37

    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.

    0 讨论(0)
  • 2021-02-03 22:38

    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

    0 讨论(0)
  • 2021-02-03 22:50

    Apparently the directory mame "C" is "invalid syntax."

    All the following variants are "invalid":

    python c:\Python34\Tools\Scripts -w c:\python\batch.py
    python c:\\Python34\\Tools\\Scripts -w c:\\python\\batch.py
    python.exe C:\Python34\Tools\Scripts\2to3.py -w C:\python\batch.py
    python.exe C:\\Python34\\Tools\\Scripts\\2to3.py -w C:\\python\\batch.py
    

    Etc. When I put in quotation marks, the closing quote is "invalid syntax."

    0 讨论(0)
提交回复
热议问题