Python 空闲:更改 Python 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4776359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 17:27:30  来源:igfitidea点击:

Python IDLE: Change Python Version

pythoneditorversionpython-idle

提问by Nathan

I have Python 2.x and 3.x on my machine (Mac OS X 10.6). For some things I want to use ver 2, but for others I want ver 3. I like the IDLE software for editing/running, but it always uses version 3.

我的机器上有 Python 2.x 和 3.x(Mac OS X 10.6)。有些事情我想用 ver 2,但有些我想用 ver 3。我喜欢 IDLE 软件来编辑/运行,但它总是使用版本 3。

Is there any way to change the version of the interpreter that IDLE uses?

有什么办法可以改变 IDLE 使用的解释器的版本吗?

Thanks!

谢谢!

采纳答案by Ned Deily

There are different versions of IDLE installed for each Python version. Depending on how you installed Python on Mac OS X, you may find different folders in /Applications. Look for a Python 3.n (n = 1 or 2) folder with an IDLE in it. Or, from a terminal command line, you may find an idle2.6and an idle3or idle3.1or idle3.2.

每个 Python 版本都安装了不同版本的 IDLE。根据您在 Mac OS X 上安装 Python 的方式,您可能会在/Applications. 查找其中包含 IDLE 的 Python 3.n(n = 1 或 2)文件夹。或者,在终端命令行中,您可能会发现idle2.6idle3idle3.1idle3.2

回答by poke

Usually each Python version installs its own version of IDLE. I don't know how this works on Mac, but for Windows it works like this:

通常每个 Python 版本都会安装自己的 IDLE 版本。我不知道这在 Mac 上是如何工作的,但对于 Windows,它是这样工作的:

python2.7 C:\Program Files\Python27\Lib\idlelib\idle.pyw

starts the Python 2 IDLE and

启动 Python 2 IDLE 和

python3.2 C:\Program Files\Python32\Lib\idlelib\idle.pyw

starts the Python 3 IDLE.

启动 Python 3 IDLE。

回答by Dowlers

In the Windows environment, if you want to use particular install of IDLE, I find the easiest way is to right click on the .pyfile and choose "open with". Then navigate to the IDLE.batfile in the Python version install location you want to use. I find picking just the ilde.pydoesn't work but the .batfile does.

在 Windows 环境下,如果你想使用特定的 IDLE 安装,我发现最简单的方法是右键单击.py文件并选择“打开方式”。然后导航到IDLE.bat要使用的 Python 版本安装位置中的文件。我发现只选择ilde.py不起作用,但.bat文件起作用。

E. g.

例如

D:\Python27\ArcGISx6410.4\Lib\idlelib\idle.bat

D:\Python27\ArcGISx6410.4\Lib\idlelib\idle.bat

or

或者

D:\Python27Desktop\ArcGIS10.4\Lib\idlelib\idle.bat

回答by Spencer H

I use Sublime 3 as my editor on mac. Several backend files required changes. Changes were made to Python3.sublime-build file:

我在 Mac 上使用 Sublime 3 作为我的编辑器。几个后端文件需要更改。对 Python3.sublime-build 文件进行了更改:

{
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf8",
"path": "/usr/local/Frameworks/Python.framework/Versions/3.3/bin/"
}

The SublimeREPL package was also installed.

还安装了 SublimeREPL 包。

The Main.sublime-menu file was edited to reflect the following:

Main.sublime-menu 文件经过编辑以反映以下内容:

{"command": "repl_open",
 "caption": "Python3 - RUN current file",
 "id": "repl_python_run",
  "mnemonic": "d",
  "args": {
        "type": "subprocess",
        "encoding": "utf8",
        "cmd": ["python3", "-u", "$file_basename"],
        "cwd": "$file_path",
        "syntax": "Packages/Python/Python.tmLanguage",
        "external_id": "python",
        "extend_env": {"PYTHONIOENCODING": "utf-8"}
        }
}

These are the major changes in a nutshell. More details with guided step-by-step instructions are available at Setting Up Sublime Text 3 for Python3 Development.

简而言之,这些是主要的变化。在为 Python3 开发设置 Sublime Text 3中提供了更多详细信息以及分步说明 。

回答by Raghavendra Phayde

If there are 2 or more Python versions installed on you computer but you can only open one Python IDLE (suppose IDLE using Python 2.7) and if you dont have IDLE for Python 3.5 installed on your computer (check the folder /usr/binfor idleor idle-python2.7And if idle-python3.5is not there then its not currently installed). Then you just have to install idle-python3.5by executing following command through CLI.

如果您的计算机上安装了 2 个或更多 Python 版本,但您只能打开一个 Python IDLE(假设 IDLE 使用 Python 2.7),并且您的计算机上没有安装 Python 3.5 的 IDLE(检查文件夹/usr/bin中的idleidle-python2.7如果idle-python3.5没有那里然后它当前没有安装)。然后你只需要idle-python3.5通过 CLI 执行以下命令来安装。

sudo apt install idle-python3.5

Or you can just install it by Software Manager in Linux. Search for IDLE and select your preferred IDLE to install.

或者你可以在 Linux 中通过软件管理器安装它。搜索 IDLE 并选择您喜欢的 IDLE 进行安装。