如何在cmd中运行不同的python版本 [英] How to run different python versions in cmd

查看:1565
本文介绍了如何在cmd中运行不同的python版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置windows命令对话框运行不同的python版本?例如,当我键入 python2 它运行python 2.7和当我键入 python3 它运行python 3.3?我知道如何配置环境变量一个版本,但两个?我的意思是像Linux终端。

How can I configure windows command dialog to run different python versions in it? For example when I type python2 it runs python 2.7 and when I type python3 it runs python 3.3? I know how to configure environment variables for one version but two? I mean something like Linux terminal.

推荐答案

Python 3.3引入了Python Launcher for Windows,安装到 c :\Windows \ 作为 py.exe pyw.exe 。安装程序还创建与 .py .pyw 的关联。然后添加#!python3 #!python2 作为第一个lline。无需向 PATH 环境变量添加任何内容。

Python 3.3 introduces Python Launcher for Windows that is installed into c:\Windows\ as py.exe and pyw.exe by the installer. The installer also creates associations with .py and .pyw. Then add #!python3 or #!python2 as the first lline. No need to add anything to the PATH environment variable.

更新:来自官方 python.org/download 的Python 3.3。它还将添加启动器。然后将第一行添加到具有 .py 扩展名的脚本中。然后,您可以通过在cmd行上输入 scriptname.py 来启动该脚本,更明确地通过 py scriptname.py c>

Update: Just install Python 3.3 from the official python.org/download. It will add also the launcher. Then add the first line to your script that has the .py extension. Then you can launch the script by simply typing the scriptname.py on the cmd line, od more explicitly by py scriptname.py, and also by double clicking on the scipt icon.

py.exe $ c> C:\PythonXX\python.exe 其中 XX 与计算机上安装的Python版本相关。说,你已将Python 2.7.6安装到 C:\ Python27 中,并将Python 3.3.3安装到 C:\Python33 。 Python启动器将使用脚本中的第一行来选择一个已安装的版本。默认(即没有明确告诉版本)是使用计算机上可用的最高版本的Python 2.

The py.exe looks for C:\PythonXX\python.exe where XX is related to the installed versions of Python at the computer. Say, you have Python 2.7.6 installed into C:\Python27, and Python 3.3.3 installed into C:\Python33. The first line in the script will be used by the Python launcher to choose one of the installed versions. The default (i.e. without telling the version explicitly) is to use the highest version of Python 2 that is available on the computer.

这篇关于如何在cmd中运行不同的python版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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