我有一个Python 2.7.11安装在我的实验室站之一。我想把Python升级到至少3.5。

我该怎么做呢? 我应该完全卸载2.7.11,而不是安装新的版本吗? 有办法更新吗?更新是个好主意吗?


当前回答

如果您正在升级任何3.x。Y到3.x。z (patch) Python版本,只需进入Python下载页面获取最新版本并开始安装。因为你的机器上已经安装了Python,安装程序会提示你“立即升级”。单击该按钮,它将用一个新版本替换现有版本。安装后还必须重新启动计算机。

如果你从3升级。X到3。y(未成年人),然后会提示“现在安装”。在这种情况下,您不是在升级,而是在安装Python的新版本。您的机器上可以安装多个版本。它们将位于不同的目录中。当你的机器上有多个Python版本时,你需要使用py启动器来启动特定版本的Python。

例如:

py -3.7

or

py -3.8

确保在您的机器上安装了py启动器。如果您使用windows安装程序的默认设置,它将自动安装。如果你在安装窗口上点击“自定义安装”链接,你可以随时检查它。

如果你的机器上安装了几个Python版本,并且你有一个项目正在使用以前版本的Python,使用虚拟环境,例如(venv),你可以在venv中使用以下方法升级Python:

升级你的虚拟环境路径

例如,我的./venv虚拟环境中有Python 3.7,我想将venv升级到Python 3.8,我会做以下工作

Python -m venv——upgrade ./venv

其他回答

在2019年,你可以使用巧克力安装。打开你的cmd或powershell,输入:

choco install python

每一个小版本的Python,都是任意3。X和2。X版本,将与其他版本并排安装在您的计算机上。只有补丁版本才会升级现有的安装。

因此,如果你想保留你已经安装的Python 2.7,那么就让它继续使用安装程序安装一个新版本。如果你想摆脱Python 2.7,你可以在安装新版本之前或之后卸载它——这没有区别。

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启动一个脚本。


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.

只要安装python最新版本的安装程序,它就会自动检测你的python版本,并提示升级python并开始升级

我能够使用以下命令执行PowerShell,并且python升级没有问题。Python -m PIP install——upgrade PIP please see image

如果您正在升级任何3.x。Y到3.x。z (patch) Python版本,只需进入Python下载页面获取最新版本并开始安装。因为你的机器上已经安装了Python,安装程序会提示你“立即升级”。单击该按钮,它将用一个新版本替换现有版本。安装后还必须重新启动计算机。

如果你从3升级。X到3。y(未成年人),然后会提示“现在安装”。在这种情况下,您不是在升级,而是在安装Python的新版本。您的机器上可以安装多个版本。它们将位于不同的目录中。当你的机器上有多个Python版本时,你需要使用py启动器来启动特定版本的Python。

例如:

py -3.7

or

py -3.8

确保在您的机器上安装了py启动器。如果您使用windows安装程序的默认设置,它将自动安装。如果你在安装窗口上点击“自定义安装”链接,你可以随时检查它。

如果你的机器上安装了几个Python版本,并且你有一个项目正在使用以前版本的Python,使用虚拟环境,例如(venv),你可以在venv中使用以下方法升级Python:

升级你的虚拟环境路径

例如,我的./venv虚拟环境中有Python 3.7,我想将venv升级到Python 3.8,我会做以下工作

Python -m venv——upgrade ./venv