如何更新 Python? [英] How to update Python?

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

问题描述

我从 2012 年初开始安装 2.7 版本.我无法就是否应该在安装最新版本之前完全卸载并擦除此版本达成共识.

软"-删除旧版本?硬删除/擦除旧版本?安装在顶部?

我在某处看到过使用 Python 安装的分段"方法的特殊安装/升级过程,将不同的版本分开和分开,但功能正常.不确定这是否是标准的、事实上的方式.

我还想知道 Revo 是否过于热心,可能会导致清除仍然需要的残余物(如环境/PATH 变量)的问题.

(Win7 x64,32 位 Python)

解决方案

更新:2018-07-06

这篇文章已经有将近 5 年的历史了!Python-2.7 将在 2020 年停止接收来自 python.org 的官方更新.此外,Python-3.7 已经发布.查看 Python-Future,了解如何使您的 Python-2 代码与 Python-3 兼容.对于更新 conda,文档现在建议在您的每个 conda 环境中使用 conda update --all 来更新该版本的所有包和 Python 可执行文件.另外,由于他们将名称更改为 Anaconda,我不知道 Windows 注册表项是否仍然相同.

更新:2017-03-24

自 2015 年 6 月以来没有对 Python(x,y) 进行更新,因此我认为可以安全地假设它已被放弃.

更新:2016-11-11

作为 @cxw 下面的评论,这些答案是针对同一位的-versions 和位版本我的意思是 64 位与 32 位.例如,这些答案适用于从 64 位 Python-2.7.10 更新到 64 位 Python-2.7.11,ie:相同 位版本.虽然可以同时安装两个不同位版本的 Python,但这需要一些技巧,所以我将把这个练习留给读者.如果不想hack,建议切换位版本时,先删除其他位版本.

更新:2016-05-16
  • AnacondaMiniConda 可以通过禁用更改 Windows PATH 和注册表.解压后,在您的 bin 中创建一个到 conda 的符号链接或从 PyPI 安装 conda.然后在 Anaconda/Miniconda 根 bin 文件夹中创建另一个名为 conda-activateactivate 的符号链接.现在 Anaconda/Miniconda 就像 Ruby RVM.只需使用 conda-activate root 来启用 Anaconda/Miniconda.
  • 不再开发或维护便携式 Python.

TL;DR

  • 使用 Anaconda 或 miniconda,然后执行 conda update --all 保持每个 conda 环境的更新,
  • 相同主要版本的官方 Python(例如 2.7.5),只需安装旧的(例如 2.7.4),
  • 不同主要版本的官方 Python(例如 3.3),与旧的并排安装,设置路径/关联指向主导(例如 2.7),快捷方式到其他(例如em> 在 BASH $ ln/c/Python33/python.exe python3).

答案取决于:

  1. 如果 OP 有 2.7.x 并且想要安装更新版本的 2.7.x,那么

    • 如果使用来自 MSI 安装程序.org/download/" rel="noreferrer">Python 官方网站,只需安装旧版本,安装程序会发出警告,将删除并替换旧版本;在控制面板"中查看已安装的程序"前后确认旧版本已被新版本替换;2.7.x 的较新版本向后兼容,因此这是完全安全的,因此恕我直言,2.7.x 的多个版本应该永远没有必要.
    • 如果从源代码构建,那么您可能应该在一个新的、干净的目录中构建,然后在新构建通过所有测试并且您确信它已成功构建后将路径指向新构建,但您可能希望保留旧版本,因为从源代码构建可能偶尔会出现问题.请参阅我的 在 Windows 上构建 Python x64 的指南7 使用 SDK 7.0.
    • 如果从诸如 Python(x,y) 之类的发行版安装,请访问他们的网站.Python(x,y) 已被放弃. 我相信可以使用他们的包管理器从 Python(x,y) 中处理更新,但是 更新也包含在他们的网站上.我找不到具体的参考资料,所以也许其他人可以谈谈这个.与 ActiveState 和 Enthought 类似,Python (x,y) 明确指出它与 Python 的其他安装不兼容:<块引用>

      建议在安装 Python(x,y) 之前卸载任何其他 Python 发行版

    • Enthought Canopy 使用 MSI 并将安装到 Program FilesEnthoughtcode> 或 homeAppDataLocalEnthoughtCanopyApp 分别适用于所有用户或每个用户.使用内置更新工具更新较新的安装.请参阅他们的文档.
    • ActiveState 还使用 MSI,因此新安装可以安装在旧安装之上.请参阅他们的安装说明.<块引用>

      其他 Python 2.7 安装 在 Windows 上,ActivePython 2.7 不能与其他 Python 2.7 安装共存(例如,从 python.org 构建的 Python 2.7).在安装 ActivePython 2.7 之前卸载任何其他 Python 2.7 安装.

    • Sage 建议安装到虚拟机中,并提供Oracle VirtualBox可用于此目的的图像文件.通过发出 sage -upgrade 命令在内部处理升级.
    • Anaconda 可以是使用 conda 命令更新:

      conda update --all

      Anaconda/Miniconda 允许用户创建环境来管理多个 Python 版本,包括 Python-2.6、2.7、3.3、3.4 和 3.5.根 Anaconda/Miniconda 安装当前基于 Python-2.7 或 Python-3.5.

      Anaconda 可能会中断任何其他 Python 安装.安装使用 MSI 安装程序.[更新:2016-05-16] Anaconda 和 Miniconda 现在使用 .exe 安装程序并提供禁用 Windows PATH 和注册表的选项改变.

      因此,根据安装方式和安装过程中选择的选项,可以在不中断现有 Python 安装的情况下安装 Anaconda/Miniconda.如果使用 .exe 安装程序并且禁用更改 Windows PATH 和注册表的选项,则任何以前的 Python 安装都将被禁用,但只需卸载 Anaconda/Miniconda 安装即可恢复原始 Python 安装,除了 Windows 注册表 PythonPythonCore 键.

      Anaconda/Miniconda 无论安装选项如何,都会进行以下注册表HKCUSoftwarePythonContinuumAnalytics 使用以下键:HelpInstallPathModulesPythonPath - 官方 Python 也注册了这些键,但在 PythonPythonCore 下.还为 AnacondaMiniconda 注册了卸载信息.除非您在安装过程中选择Register with Windows"选项,否则它不会创建 PythonCore,因此像 Python Tools for Visual Studio 这样的集成不会自动看到 Anaconda/Miniconda.如果启用了注册 Anaconda/Miniconda 的选项,那么我认为您现有的 Python Windows 注册表项将被更改并且卸载可能无法恢复它们.

    • WinPython 更新,我认为可以通过 WinPython 控制面板.
    • PortablePython 不再开发.它没有更新方法.可能的更新可以解压到一个新目录,然后 Applibsite-packagesAppScripts 可以复制到新安装,但如果没有工作然后重新安装所有软件包可能是必要的.使用 pip list 查看安装了哪些软件包及其版本.有些是由 PortablePython 安装的.如果未安装 pip,请使用 easy_install pip 安装.
  2. 如果 OP 有 2.7.x 并且想要安装不同的版本,例如 <=2.6.x 或 >=3.xx,然后并排安装不同的版本很好.您必须选择要与 *.py 文件关联的 Python 版本(如果有)以及您希望在路径中使用的 Python 版本,但如果您使用 BASH.AFAIK 2.7.x 向后兼容 2.6.x,所以恕我直言并排安装不是必需的,但是 Python-3.xx 不向后兼容,所以我的建议是将 Python-2.7 放在你的路径上并有Python-3 通过创建一个名为 python3 的可执行文件的快捷方式成为一个可选版本(这是 Linux 上的常见设置).Windows 上的官方 Python 默认安装路径是

    • C:Python33 for 3.3.x(最新版本 2013-07-29)
    • C:Python32 for 3.2.x
    • &c.
    • C:Python27 for 2.7.x(最新版本 2013-07-29)
    • C:Python26 for 2.6.x
    • &c.
  3. 如果 OP 不更新 Python,而只是更新包,他们可能希望查看 virtualenv 将特定于其开发项目的不同版本的包分开.Pip 也是一个很棒的软件包更新工具.如果软件包使用二进制安装程序,我通常会在安装新软件包之前先卸载旧软件包.

我希望这能消除任何困惑.

I have version 2.7 installed from early 2012. I can't find any consensus on whether I should completely uninstall and wipe this version before putting on the latest version.

"Soft"-removing old versions? Hard-removing/wiping old versions? Installing over top?

I've seen somewhere a special install/upgrade process using a "segmenting" method of Python installations, keeping different versions separate and apart, but functional. Not sure if this is the standard, de facto way.

I also wonder if Revo gets too overzealous and may cause issues with wiping out still-needed remnants, like environment/PATH variables.

(Win7 x64, 32-bit Python)

解决方案

UPDATE: 2018-07-06

This post is now nearly 5 years old! Python-2.7 will stop receiving official updates from python.org in 2020. Also, Python-3.7 has been released. Check out Python-Future on how to make your Python-2 code compatible with Python-3. For updating conda, the documentation now recommends using conda update --all in each of your conda environments to update all packages and the Python executable for that version. Also, since they changed their name to Anaconda, I don't know if the Windows registry keys are still the same.

UPDATE: 2017-03-24

There have been no updates to Python(x,y) since June of 2015, so I think it's safe to assume it has been abandoned.

UPDATE: 2016-11-11

As @cxw comments below, these answers are for the same bit-versions, and by bit-version I mean 64-bit vs. 32-bit. For example, these answers would apply to updating from 64-bit Python-2.7.10 to 64-bit Python-2.7.11, ie: the same bit-version. While it is possible to install two different bit versions of Python together, it would require some hacking, so I'll save that exercise for the reader. If you don't want to hack, I suggest that if switching bit-versions, remove the other bit-version first.

UPDATES: 2016-05-16
  • Anaconda and MiniConda can be used with an existing Python installation by disabling the options to alter the Windows PATH and Registry. After extraction, create a symlink to conda in your bin or install conda from PyPI. Then create another symlink called conda-activate to activate in the Anaconda/Miniconda root bin folder. Now Anaconda/Miniconda is just like Ruby RVM. Just use conda-activate root to enable Anaconda/Miniconda.
  • Portable Python is no longer being developed or maintained.

TL;DR

  • Using Anaconda or miniconda, then just execute conda update --all to keep each conda environment updated,
  • same major version of official Python (e.g. 2.7.5), just install over old (e.g. 2.7.4),
  • different major version of official Python (e.g. 3.3), install side-by-side with old, set paths/associations to point to dominant (e.g. 2.7), shortcut to other (e.g. in BASH $ ln /c/Python33/python.exe python3).

The answer depends:

  1. If OP has 2.7.x and wants to install newer version of 2.7.x, then

    • if using MSI installer from the official Python website, just install over old version, installer will issue warning that it will remove and replace the older version; looking in "installed programs" in "control panel" before and after confirms that the old version has been replaced by the new version; newer versions of 2.7.x are backwards compatible so this is completely safe and therefore IMHO multiple versions of 2.7.x should never necessary.
    • if building from source, then you should probably build in a fresh, clean directory, and then point your path to the new build once it passes all tests and you are confident that it has been built successfully, but you may wish to keep the old build around because building from source may occasionally have issues. See my guide for building Python x64 on Windows 7 with SDK 7.0.
    • if installing from a distribution such as Python(x,y), see their website. Python(x,y) has been abandoned. I believe that updates can be handled from within Python(x,y) with their package manager, but updates are also included on their website. I could not find a specific reference so perhaps someone else can speak to this. Similar to ActiveState and probably Enthought, Python (x,y) clearly states it is incompatible with other installations of Python:

      It is recommended to uninstall any other Python distribution before installing Python(x,y)

    • Enthought Canopy uses an MSI and will install either into Program FilesEnthought or homeAppDataLocalEnthoughtCanopyApp for all users or per user respectively. Newer installations are updated by using the built in update tool. See their documentation.
    • ActiveState also uses an MSI so newer installations can be installed on top of older ones. See their installation notes.

      Other Python 2.7 Installations On Windows, ActivePython 2.7 cannot coexist with other Python 2.7 installations (for example, a Python 2.7 build from python.org). Uninstall any other Python 2.7 installations before installing ActivePython 2.7.

    • Sage recommends that you install it into a virtual machine, and provides a Oracle VirtualBox image file that can be used for this purpose. Upgrades are handled internally by issuing the sage -upgrade command.
    • Anaconda can be updated by using the conda command:

      conda update --all
      

      Anaconda/Miniconda lets users create environments to manage multiple Python versions including Python-2.6, 2.7, 3.3, 3.4 and 3.5. The root Anaconda/Miniconda installations are currently based on either Python-2.7 or Python-3.5.

      Anaconda will likely disrupt any other Python installations. Installation uses MSI installer. [UPDATE: 2016-05-16] Anaconda and Miniconda now use .exe installers and provide options to disable Windows PATH and Registry alterations.

      Therefore Anaconda/Miniconda can be installed without disrupting existing Python installations depending on how it was installed and the options that were selected during installation. If the .exe installer is used and the options to alter Windows PATH and Registry are not disabled, then any previous Python installations will be disabled, but simply uninstalling the Anaconda/Miniconda installation should restore the original Python installation, except maybe the Windows Registry PythonPythonCore keys.

      Anaconda/Miniconda makes the following registry edits regardless of the installation options: HKCUSoftwarePythonContinuumAnalytics with the following keys: Help, InstallPath, Modules and PythonPath - official Python registers these keys too, but under PythonPythonCore. Also uninstallation info is registered for AnacondaMiniconda. Unless you select the "Register with Windows" option during installation, it doesn't create PythonCore, so integrations like Python Tools for Visual Studio do not automatically see Anaconda/Miniconda. If the option to register Anaconda/Miniconda is enabled, then I think your existing Python Windows Registry keys will be altered and uninstallation will probably not restore them.

    • WinPython updates, I think, can be handled through the WinPython Control Panel.
    • PortablePython is no longer being developed. It had no update method. Possibly updates could be unzipped into a fresh directory and then Applibsite-packages and AppScripts could be copied to the new installation, but if this didn't work then reinstalling all packages might have been necessary. Use pip list to see what packages were installed and their versions. Some were installed by PortablePython. Use easy_install pip to install pip if it wasn't installed.
  2. If OP has 2.7.x and wants to install a different version, e.g. <=2.6.x or >=3.x.x, then installing different versions side-by-side is fine. You must choose which version of Python (if any) to associate with *.py files and which you want on your path, although you should be able to set up shells with different paths if you use BASH. AFAIK 2.7.x is backwards compatible with 2.6.x, so IMHO side-by-side installs is not necessary, however Python-3.x.x is not backwards compatible, so my recommendation would be to put Python-2.7 on your path and have Python-3 be an optional version by creating a shortcut to its executable called python3 (this is a common setup on Linux). The official Python default install path on Windows is

    • C:Python33 for 3.3.x (latest 2013-07-29)
    • C:Python32 for 3.2.x
    • &c.
    • C:Python27 for 2.7.x (latest 2013-07-29)
    • C:Python26 for 2.6.x
    • &c.
  3. If OP is not updating Python, but merely updating packages, they may wish to look into virtualenv to keep the different versions of packages specific to their development projects separate. Pip is also a great tool to update packages. If packages use binary installers I usually uninstall the old package before installing the new one.

I hope this clears up any confusion.

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

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