如何从命令行在python 2.7到python 3之间切换? [英] How to switch between python 2.7 to python 3 from command line?
问题描述
我试图找到最好的方式在两个python编译器之间切换2.7到3.3
如果我从cmd运行python,我会使用像
I'm trying to find the best way to switch between the two python compilers 2.7 to 3.3 If I run python from cmd, I would you use something like
python ex1.py
其中我从窗口环境变量设置python从我的计算机属性指向python 3.3或2.7一个或另一个。
where I set "python" from window environment variable from my computer properties to point to either python 3.3 or 2.7 one or another.
我想知道有一个简单的方法从两个cmd之间切换?
I am wondering there is an easy way to switch between the two from cmd line ?
推荐答案
对于Windows 7,我只是重命名 python.exe
将Python 3文件夹更改为 python3.exe
并将路径添加到环境变量中。使用它,我可以执行 python test_script.py
,脚本使用Python 2.7运行,当我执行 python3 test_script.py
,它运行Python 3中的脚本。
For Windows 7, I just rename the python.exe
from the Python 3 folder to python3.exe
and add the path into the environment variables. Using that, I can execute python test_script.py
and the script runs with Python 2.7 and when I do python3 test_script.py
, it runs the script in Python 3.
要将 Python 3
添加到环境变量,请按照下列步骤 -
To add Python 3
to the environment variables, follow these steps -
- 右键点击我的电脑,然后转到
属性
。 - 转到
高级系统设置
。 - 单击
环境变量
并编辑PATH
并将路径添加到您的Python 3安装目录。
- Right Click on My Computer and go to
Properties
. - Go to
Advanced System Settings
. - Click on
Environment Variables
and editPATH
and add the path to your Python 3 installation directory.
例如,
这篇关于如何从命令行在python 2.7到python 3之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!