在cmd中调用python的早期版本

时间:2022-03-20 18:42:14

I've installed Python 2.7 and python 3.4 on my system. Earlier i was using 3.4 but now require 2.7 as well (for a course I'm taking, which requires some files which are not there for 3.4). When I type python in cmd it by default initializes 3.4. Is there some way to change it to 2.7 by default?

我在我的系统上安装了Python 2.7和python 3.4。早些时候我使用的是3.4,但现在也需要2.7(对于我正在学习的课程,这需要一些不存在3.4的文件)。当我在cmd中键入python时,它默认初始化为3.4。有没有办法在默认情况下将其更改为2.7?

Thanks

UPDATE: I was able to invoke it using 'py'. Here's the link if anyone else has a confusion. https://docs.python.org/3/using/windows.html?highlight=shebang#python-launcher-for-windows (from some other answer)

更新:我能够使用'py'调用它。如果其他人有混淆,这是链接。 https://docs.python.org/3/using/windows.html?highlight=shebang#python-launcher-for-windows(来自其他答案)

1 个解决方案

#1


Update: If your system environment is Windows:

更新:如果您的系统环境是Windows:

1) call py -2.7 or py -3 based on the version you want.

1)根据你想要的版本调用py -2.7或py -3。

2) change your PATH system environment variable , makes sure it refers to the version you want.

2)更改PATH系统环境变量,确保它引用您想要的版本。

You can do it in serveral ways on Linux environment:

您可以在Linux环境中以多种方式执行此操作:

1) call a specific Python binary you can call the explicit full path (e. g. /usr/local/bin/python). This will call the same executable regardless of the value of the $PATH variable.

1)调用特定的Python二进制文件,您可以调用显式完整路径(例如/ usr / local / bin / python)。无论$ PATH变量的值如何,这都将调用相同的可执行文件。

2) configure your accounts so that both have the same binary first in the $PATH variable.

2)配置您的帐户,以便两者在$ PATH变量中首先具有相同的二进制文件。

3) call python2 and python3; many installations symlink these to the corresponding binaries.

3)调用python2和python3;许多安装符号链接到相应的二进制文件。

$ python2
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

#1


Update: If your system environment is Windows:

更新:如果您的系统环境是Windows:

1) call py -2.7 or py -3 based on the version you want.

1)根据你想要的版本调用py -2.7或py -3。

2) change your PATH system environment variable , makes sure it refers to the version you want.

2)更改PATH系统环境变量,确保它引用您想要的版本。

You can do it in serveral ways on Linux environment:

您可以在Linux环境中以多种方式执行此操作:

1) call a specific Python binary you can call the explicit full path (e. g. /usr/local/bin/python). This will call the same executable regardless of the value of the $PATH variable.

1)调用特定的Python二进制文件,您可以调用显式完整路径(例如/ usr / local / bin / python)。无论$ PATH变量的值如何,这都将调用相同的可执行文件。

2) configure your accounts so that both have the same binary first in the $PATH variable.

2)配置您的帐户,以便两者在$ PATH变量中首先具有相同的二进制文件。

3) call python2 and python3; many installations symlink these to the corresponding binaries.

3)调用python2和python3;许多安装符号链接到相应的二进制文件。

$ python2
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>