python2程序在python3下运行_Python 2和Python 3-在命令提示符下运行

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 already took python script.py, so ideally python3 script.py should invoke Python 3.

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.

Make sure the Python 3 folder is present in the PATH environment variable.

Locate the "python.exe" file in the Python 3 folder.

Copy and Paste the "python.exe" file within the Python 3 folder.

Rename the copied file to "python3" (or whatever you want the command to be).

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

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.

I hope this helps!

EDIT:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值