如何升级 Windows 10 中的 Python 安装? [英] How do I upgrade the Python installation in Windows 10?

查看:39
本文介绍了如何升级 Windows 10 中的 Python 安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个实验室工作站上安装了 Python 2.7.11.我想将 Python 升级到至少 3.5.

I have a Python 2.7.11 installed on one of my LAB stations. I would like to upgrade Python to at least 3.5.

我该怎么做?我应该更喜欢完全卸载 2.7.11 而不是安装新的吗?有没有办法更新它?更新是个好主意吗?

How should I do that ? Should I prefer to completely uninstall 2.7.11 and than install the new one ? Is there a way to update it ? Is an update a good idea ?

推荐答案

Python 的每个次要版本,即任何 3.x 和 2.x 版本,都将与您计算机上的其他版本并行安装.只有补丁版本会升级现有安装.

Every minor version of Python, that is any 3.x and 2.x version, will install side-by-side with other versions on your computer. Only patch versions will upgrade existing installations.

因此,如果您想保留已安装的 Python 2.7,那么只需让它使用安装程序安装新版本即可.如果你想摆脱 Python 2.7,你可以在安装新版本之前或之后卸载它——这没有区别.

So if you want to keep your installed Python 2.7 around, then just let it and install a new version using the installer. If you want to get rid of Python 2.7, you can uninstall it before or after installing a newer version—there is no difference to this.

当前的 Python 3 安装带有 py.exe 启动器,默认情况下安装到系统目录中.这使得它可以从 PATH 中使用,因此您可以通过使用 py 而不是 python 作为命令从任何 shell 自动运行它.这避免了您必须自己将当前的 Python 安装放入 PATH 中.这样,您可以轻松地并排安装多个 Python,而不会相互干扰.运行时,只需使用 py script.py 而不是 python script.py 即可使用启动器.您还可以使用例如 py -3py -3.6 指定版本来启动特定版本,否则启动器将使用当前默认值(通常是最新的 3.x).

Current Python 3 installations come with the py.exe launcher, which by default is installed into the system directory. This makes it available from the PATH, so you can automatically run it from any shell just by using py instead of python as the command. This avoids you having to put the current Python installation into PATH yourself. That way, you can easily have multiple Python installations side-by-side without them interfering with each other. When running, just use py script.py instead of python script.py to use the launcher. You can also specify a version using for example py -3 or py -3.6 to launch a specific version, otherwise the launcher will use the current default (which will usually be the latest 3.x).

如果您决定保留 Python 2.7 安装,您还可以使用启动器运行 Python 2 脚本(这些脚本通常与 Python 3 的语法不兼容).只需使用 py -2 script.py 来启动脚本.

Using the launcher, you can also run Python 2 scripts (which are often syntax incompatible to Python 3), if you decide to keep your Python 2.7 installation. Just use py -2 script.py to launch a script.

至于 PyPI 包,每个 Python 安装都有自己的文件夹,模块安装到其中.因此,如果您安装新版本并希望使用为以前版本安装的模块,则必须先为新版本安装它们.当前版本的安装程序还提供您安装 pip 的机会;默认情况下它是启用的,因此您已经为每个安装安装了 pip.除非您明确地将 Python 安装添加到 PATH,否则您不能只使用 pip.幸运的是,您也可以简单地使用 py.exe 启动器:py -m pip 运行 pip.例如,要为 Python 3.6 安装 Beautiful Soup,您可以运行 py -3.6 -m pip install beautifulsoup4.

As for PyPI packages, every Python installation comes with its own folder where modules are installed into. So if you install a new version and you want to use modules you installed for a previous version, you will have to install them first for the new version. Current versions of the installer also offer you to install pip; it’s enabled by default, so you already have pip for every installation. Unless you explicitly add a Python installation to the PATH, you cannot just use pip though. Luckily, you can also simply use the py.exe launcher for this: py -m pip runs pip. So for example to install Beautiful Soup for Python 3.6, you could run py -3.6 -m pip install beautifulsoup4.

这篇关于如何升级 Windows 10 中的 Python 安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆