[英]How to upgrade to Python 3.3?
I just installed Ubuntu 12.04 and wish to use Python 3.3 rather than 2.7 which is currently installed. 我刚刚安装了Ubuntu 12.04,并希望使用Python 3.3而不是当前已安装的2.7。 I downloaded python from python's ftp and installed it.
我从python的ftp下载了python并安装了它。 I followed the steps given in : https://askubuntu.com/questions/244544/how-to-install-python-3-3
我按照以下步骤进行操作: https : //askubuntu.com/questions/244544/how-to-install-python-3-3
Now I have Python 3.3 installed in /opt/python3.3 and create sym links for it as told in this URL. 现在,我在/opt/python3.3中安装了Python 3.3,并按照此URL中的说明为其创建了符号链接。 Still python --version command tells me that my current version is 2.7.3.
仍然python --version命令告诉我我的当前版本是2.7.3。
What's wrong? 怎么了?
代替使用python
在终端使用python3.3
Python 3.x and 2.x are incompatible languages. Python 3.x和2.x是不兼容的语言。
PEP 394 — The "python" Command on Unix-Like Systems contains recommendations for how to handle this fact. PEP 394 — Unix-like Systems上的“ python”命令包含有关如何处理此事实的建议。 The short version is this:
简短的版本是这样的:
python
should refer to the latest Python 2.x. python
应该参考最新的Python2.x。 python3
should always refer to the latest Python 3.x. python3
应该始终引用最新的Python3.x。 python2
should refer to the latest Python 2.x (and must if python
refers to 3.x), but often doesn't. python2
应该引用最新的Python 2.x(如果python
引用3.x,则必须引用),但通常不是。 pythonX.Y
should always refer to Python XY pythonX.Y
应该始终引用Python XY So, running python3
or python3.3
should run your custom 3.3 installation, but python
should run your platform's standard 2.7. 因此,运行
python3
或python3.3
应该运行自定义3.3安装,但是python
应该运行平台的标准2.7。
The Rationale and Migration Notes sections explain why the first rule is as it is, but the short version is this: There are millions of scripts out there—some integral to the functional of various OS distros or third-party packages—that assume /usr/bin/env python
runs Python 2.x, and no scripts that assume it runs Python 3.x. “基本原理和迁移说明”部分解释了为什么第一个规则保持原样的原因,但简短的版本是这样的:那里有数百万个脚本(某些操作系统发行版或第三方软件包的功能不可或缺的一部分)假定
/usr/bin/env python
运行Python 2.x,并且没有脚本假定它运行Python3.x。
So, your best bet is to leave things the way your distro wanted, and explicitly use python3
to refer to your 3.3 installation. 因此,最好的选择是按照发行版希望的方式进行操作,并明确使用
python3
来引用3.3安装。 (And, likewise, pip3
, ipython3
, idle3
, etc.) (同样,
pip3
, ipython3
, idle3
等)
The specific instructions you followed also create a link named py
. 您遵循的特定说明还创建了一个名为
py
的链接。 This is definitely non-standard, but I can see how it would be convenient. 这绝对是非标准的,但是我可以看到它会带来什么便利。 If you want to do this, go for it—then, instead of running
python
, just run py
. 如果您想这样做,那就去做吧-然后,不用运行
python
,只需运行py
。
(However, you still want to make sure you get links named python3.3
and python3
onto the path, so you have a PEP-394-compliant installation. If those instructions don't do that for you, do it manually after you're done.) (但是,您仍然要确保在路径上获取名为
python3.3
和python3
链接,因此您具有符合PEP-394的安装。如果这些说明不适合您,请在安装后手动进行重做。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.