擅长:python、mysql、java
<p>通过在python.exe文件所在的同一目录中创建批处理文件(假设该目录已经在windows路径上-不必是该目录,它只是一个方便的、相对逻辑的位置),可以将2to3.py设置为在键入2to3时作为命令运行。</p>
<p>假设您在<code>C:\Python33</code>中安装了python。如果您不确定python安装在哪里,可以通过在命令行中键入<code>where python</code>来找出Windows认为它在哪里。</p>
<p>你应该在<code>C:\Python33</code>中有<code>python.exe</code>,在<code>C:\Python33\Tools\Scripts</code>中有<code>2to3.py</code>。</p>
<p>在<code>C:\Python33\Scripts</code>中创建一个名为<code>2to3.bat</code>的批处理文件,并将这一行放入批处理文件中</p>
<pre><code>@python "%~dp0\..\Tools\Scripts\2to3.py" %*
</code></pre>
<p><code>%~dp0</code>是批处理文件的位置,在本例中是<code>c:\Python33\Scripts</code>,<code>%*</code>将所有参数从命令行传递给<code>2to3.py</code>脚本。保存.bat文件后,您应该能够从命令行键入<code>2to3</code>,并查看</p>
<pre><code>At least one file or directory argument required.
Use --help to show usage.
</code></pre>
<p>在从setup.py安装时,我发现这项技术很有用,因为有时安装脚本希望2to3作为命令可用。</p>