简体   繁体   English

Python 2to3 windows CMD

[英]Python 2to3 windows CMD

I have installed python 32 package to the 我已经安装了python 32包

C:\\python32 C:\\ python32

I have also set the paths: 我也设置了路径:

PYTHONPATH | PYTHONPATH | C:\\Python32\\Lib;C:\\Python32\\DLLs;C:\\Python32\\Lib\\lib-tk; C:\\ Python32 \\库; C:\\ Python32 \\的DLL; C:\\ Python32 \\ LIB \\ LIB-TK;

PATH ;C:\\Python32; 路径; C:\\ Python32;

I would like to use the "2to3" tool, but CMD does not recognize it. 我想使用“2to3”工具,但CMD无法识别它。

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

Should i add an extra path for "2to3" or something? 我应该为“2to3”添加额外的路径吗?

Thanks 谢谢

2to3 is actually a Python script found in the Tools/scripts folder of your Python install. 2to3实际上是Python安装的Tools / scripts文件夹中的Python脚本。

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 有关详细信息,请参阅此处: http//docs.python.org/library/2to3.html

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). 通过在与python.exe文件相同的目录中创建批处理文件,可以设置2to3.py作为命令运行,方法是在您的Windows路径中创建一个批处理文件(假设该目录已经在您的Windows路径上 - 它不一定是这个目录它只是一个方便,相对合理的点)。

Lets assume you have python installed in C:\\Python33 . 让我们假设你在C:\\Python33安装了python。 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. 如果您不确定python安装的位置,可以通过在命令行输入where python来查找Windows认为的where python

You should have python.exe in C:\\Python33 and 2to3.py in C:\\Python33\\Tools\\Scripts . 你应该有python.exeC:\\Python332to3.pyC:\\Python33\\Tools\\Scripts

Create a batch file called 2to3.bat in C:\\Python33\\Scripts and put this line in the batch file C:\\Python33\\Scripts创建一个名为2to3.bat的批处理文件,并将此行放在批处理文件中

@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. %~dp0是批处理文件的位置,在本例中为c:\\Python33\\Scripts%*将所有参数从命令行传递给2to3.py脚本。 After you've saved the .bat file, you should be able to type 2to3 from the command line and see 保存.bat文件后,您应该能够从命令行键入2to3并查看

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. 我发现这个技术在从setup.py安装时很有用,因为有时候安装脚本希望2to3可用作命令。

Apparently the directory mame "C" is "invalid syntax." 显然目录mame“C”是“语法无效”。

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." 等等。当我输入引号时,结束语是“语法无效”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM