如何从命令行在 python 2.7 和 python 3 之间切换? [英] How to switch between python 2.7 to python 3 from command line?

查看:21
本文介绍了如何从命令行在 python 2.7 和 python 3 之间切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到在两个 python 编译器 2.7 到 3.3 之间切换的最佳方法.我像这样从 cmd 运行 python 脚本:

<块引用>

python ex1.py

我在哪里设置窗口环境变量中的python"环境以指向 python 3.3 或 2.7?

我想知道是否有一种简单的方法可以从 cmd 行在两个版本之间切换?

解决方案

对于 Windows 7,我只是将 Python 3 文件夹中的 python.exe 重命名为 python3.exe> 并将路径添加到环境变量中.使用它,我可以执行 python test_script.py 并且脚本在 Python 2.7 上运行,当我执行 python3 test_script.py 时,它在 Python 3 中运行脚本.>

要将 Python 3 添加到环境变量,请按照以下步骤操作 -

  1. 右键单击我的电脑并转到属性.
  2. 转到高级系统设置.
  3. 单击Environment Variables 并编辑PATH 并将路径添加到您的Python 3 安装目录.

例如

I'm trying to find the best way to switch between the two python compilers, 2.7 to 3.3. I ran the python script from the cmd like this:

python ex1.py

Where do I set the "python" environment in the window's environment variable to point to either python 3.3 or 2.7?

I am wondering if there is an easy way to switch between the two versions from the cmd line?

解决方案

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.

To add Python 3 to the environment variables, follow these steps -

  1. Right Click on My Computer and go to Properties.
  2. Go to Advanced System Settings.
  3. Click on Environment Variables and edit PATH and add the path to your Python 3 installation directory.

For example,

这篇关于如何从命令行在 python 2.7 和 python 3 之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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