Python 2和Python 3-在命令提示符下运行 [英] Python 2 and Python 3 - Running in Command Prompt

查看:136
本文介绍了Python 2和Python 3-在命令提示符下运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python 2和Python 3中都有各种项目(同时安装了两个python版本),我一直在寻找一种比
py -3脚本更直观的方式来通过命令提示符运行脚本.py

Having various projects in both Python 2 and Python 3 (with both python versions installed), I was looking for a more intuitive way to run scripts via Command Prompt than py -3 script.py.

Python 2已经采用了 python script.py ,因此理想情况下 python3 script.py 应该调用Python 3。

Python 2 already took python script.py, so ideally python3 script.py should invoke Python 3.

我的问题:如何添加 python3 作为命令提示符命令?

My question: How can I add python3 as a Command Prompt command?

推荐答案

搜索没有产生良好的结果,所以我认为我应该与以后寻找它的人分享我的过程。

Searching did not yield good results, so I thought I should share the process I took with anyone looking for this in the future.


  1. 确保PATH环境变量中存在Python 3文件夹。

  2. 在Python 3文件夹中找到 python.exe文件。

  3. 在Python 3中复制并粘贴 python.exe文件文件夹。

  4. 将复制的文件重命名为 python3(或任何您想要的命令)。

  1. Make sure the Python 3 folder is present in the PATH environment variable.
  2. Locate the "python.exe" file in the Python 3 folder.
  3. Copy and Paste the "python.exe" file within the Python 3 folder.
  4. Rename the copied file to "python3" (or whatever you want the command to be).

现在,当您在命令提示符下输入 python3 script.py 时,脚本将遍历复制的Python 3文件。

Now, when you input python3 script.py to Command Prompt, the script will run through the copied Python 3 file.

此外,通过复制python.exe(而不是重命名),您可以允许其他解释器(例如PyCharm)继续使用其默认的 python.exe路径设置。

Also, by copying python.exe (instead of renaming it) you allow other interpreters - such as PyCharm - to continue using their default "python.exe" path settings.

我希望这会有所帮助!

编辑:

符号链接具有相同的效果,但会使事情保持整洁。

A "symlink" has the same effect, but keeps things a bit tidier.

这篇关于Python 2和Python 3-在命令提示符下运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆