How to upgrade to Python 3.3?

China☆狼群 提交于 2019-12-12 04:35:28

问题


I just installed Ubuntu 12.04 and wish to use Python 3.3 rather than 2.7 which is currently installed. I downloaded python from python's ftp and installed it. I followed the steps given in : 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. Still python --version command tells me that my current version is 2.7.3.

What's wrong?


回答1:


Instead of using python in terminal use python3.3




回答2:


Python 3.x and 2.x are incompatible languages.

PEP 394 — The "python" Command on Unix-Like Systems contains recommendations for how to handle this fact. The short version is this:

  • python should refer to the latest Python 2.x.
  • python3 should always refer to the latest Python 3.x.
  • python2 should refer to the latest Python 2.x (and must if python refers to 3.x), but often doesn't.
  • pythonX.Y should always refer to Python X.Y.

So, running python3 or python3.3 should run your custom 3.3 installation, but python should run your platform's standard 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.

So, your best bet is to leave things the way your distro wanted, and explicitly use python3 to refer to your 3.3 installation. (And, likewise, pip3, ipython3, idle3, etc.)


The specific instructions you followed also create a link named 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.

(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.)



来源:https://stackoverflow.com/questions/18259403/how-to-upgrade-to-python-3-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!