如何在Mac上使用Python 3.X做好准备?

7 投票
1 回答
2220 浏览
提问于 2025-04-17 05:17

我在OS X上下载了Python 3.2,并把它安装在了我的硬盘上。但是问题是,当我打开终端,输入python的时候……

它还是显示旧版本,像这样:

Python 2.6.1 (r261:67515, 2010年6月24日, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] 在darwin上 输入"help", "copyright", "credits"或 "license"获取更多信息。

然后,我去Python的文件夹里,发现了一个这样的文件:

Update Shell Profile.command

于是,我运行了它,显示了一些内容,像这样:

/Applications/Python\ 3.2/Update\ Shell\ Profile.command ; exit;
Users-MacBook:~ User$ /Applications/Python\ 3.2/Update\ Shell\ Profile.command ; exit;
This script will update your shell profile when the 'bin' directory
of python is not early enough of the PATH of your shell.
These changes will be effective only in shell windows that you open
after running this script.
All right, you're a python lover already
logout

[Process compleUser]

但是我在终端里还是无法使用Python 3.2。我是不是做错了什么?谢谢。

1 个回答

9

在你的终端里,输入 python3

在类Unix系统中,通常系统默认使用的是Python 2.x版本。但是,Python 2和Python 3之间的语法变化很大,导致它们不兼容。因此,你不能用Python 3替代系统中的Python 2,否则可能会完全破坏一些重要的系统软件包。

所以,Python 3的解释器通过 python3 这个命令来区分旧的Python 2解释器。

撰写回答