【问题标题】:Unable to upgrade Python on Red Hat Linux无法在 Red Hat Linux 上升级 Python
【发布时间】:2014-10-29 17:34:32
【问题描述】:

我有 Python 2.6.6。在我的 Red Hat Linux VM 上运行某个脚本。需要升级到 3.4.1。试过了

easy_install --upgrade python

但我总是得到

bash-4.1# easy_install --upgrade python
Searching for python
Reading http://pypi.python.org/simple/python/
Reading http://www.python.org
Reading http://www.python.org/2.3
Reading http://www.python.org/2.4
Reading http://www.python.org/2.4.1
Reading http://www.python.org/2.5
Reading http://www.python.org/download/
Best match: Python 3.4.1
Downloading https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz
Processing Python-3.4.1.tgz
Running Python-3.4.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Qd_HVP/Python-3.4.1/egg-dist-tmp-iqaG4H
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 9, in <module>
    load_entry_point('distribute==0.6.10', 'console_scripts', 'easy_install')()
  File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 1715, in main
    with_ei_usage(lambda:
  File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 1696, in with_ei_usage
    return f()
  File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 1719, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 236, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 472, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 502, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 681, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 958, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 947, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python2.6/site-packages/setuptools/sandbox.py", line 29, in run_setup
    lambda: execfile(
  File "/usr/lib/python2.6/site-packages/setuptools/sandbox.py", line 70, in run
    return func()
  File "/usr/lib/python2.6/site-packages/setuptools/sandbox.py", line 31, in <lambda>
    {'__file__':setup_script, '__name__':'__main__'}
  File "setup.py", line 1865
    exec(f.read(), globals(), fficonfig)
SyntaxError: unqualified exec is not allowed in function 'configure_ctypes' it contains a nested function with free variables
bash-4.1# SyntaxError: unqualified exec is not allowed in function 'configure_ctypes' it contains a nested function with free variables

当然,我不能从机器中删除 Python 2.6.6,因为很多系统脚本都依赖它。有什么想法吗?

【问题讨论】:

  • 简易安装用于升级包。选中此项以安装 Python 3 stackoverflow.com/questions/8087184/installing-python3-on-rhel
  • “当然,我不能从机器上删除 Python 2.6.6,因为很多系统脚本都依赖它。”根据定义,这意味着您无法升级它。你可以做的是并排安装一个新的。幸运的是,Python 可以很容易地拥有两个不同的次要版本,甚至更容易拥有两个不同的主要版本。例如,您可以使用python3python3.4 运行3.4 版本,即使2.6 在您的PATH 上更高,并且脚本(easy_installpipipython 等)将得到类似的处理.
  • 使用虚拟环境
  • 我正在使用来自问题stackoverflow.com/questions/8087184/installing-python3-on-rhel 的答案,即手动安装它。只有一件事不清楚。它不会改变python -V 返回的值。我的 python 脚本正在由自动化工具运行。它将尝试使用它找到的默认 python。不知道该走哪条路。
  • 好的。我做到了,手动安装。我现在如何使用它?我的自动化工具如何知道要使用哪个 python?

标签: python linux redhat


【解决方案1】:

我通常建议不要在 RPM 管理的发行版(例如 RHEL)上手动升级软件包。如果需要升级,只能通过 rpm 升级来完成。 rpm 工具存在以及使用它是有原因的。其实不止一个原因。它有一个重要的用途,手动安装或升级包完全颠覆了它。

如果绝对必要,应按以下步骤进行:

  1. 获取 Red Hat 的 python 包的源 RPM。
  2. 获取新版python源码。
  3. 找出 Red Hat 的 python RPM 中的哪些补丁(如果有)仍然适用于新版本的 python。
  4. 使用 python RPM 中的 spec 文件来构建带有新版本 python 的 rpm。
  5. 希望第 4 步有效。如果是这样,耶!安装它。如果不是,找出原因,根据需要修补规范文件,返回步骤 #4。
  6. 您现在安装了新版本的 python。检查其他使用 python 的 RHEL rpm 是否与新版本中断。如果没有,耶!你完成了。如果有什么东西坏了,想办法解决它。

许多 RHEL 系统管理工具和脚本都使用 Python。由于安装了新的 python 包,某些东西最终被破坏并不是完全不可能的。

使用 RHEL 的全部原因是拥有一个商业支持的稳定 Linux 发行版,其所有组件都经过了互操作性测试。升级它的随机部分会错过拥有 RHEL 的全部意义;通常您会升级到全新的 RHEL 版本,而不是单个软件包;但是,各有各的……

【讨论】:

    【解决方案2】:

    Red Hat 提供多个版本的 Python(和其他软件包),可以作为软件集合的一部分并行安装。它们使系统 /usr/bin/ 保持不变,并受到 Red Hat 的支持。

    您需要: * 启用 RHSCL 和可选的软件仓库 * 那么你可以yum install rh-python36python27 (2.7.13) * 使用scl enable rh-python 36 bash 将 python 添加到您的路径中。

    How to install Python 3 on RHEL。它涵盖了使用多个 Python 版本、Python 虚拟环境和软件集合的许多技巧。

    【讨论】:

      【解决方案3】:

      您需要找到 Python-3.4 软件包的源代码,或自行构建。

      快速搜索发现 http://wiki.guibin.info/?p=133 用于自己构建 Python-3.4。

      通过更多搜索,您也许能够找到 RPM 包的来源,但当然取决于您对这些包的信任程度——我不会在生产中使用随机 RPM!

      【讨论】:

        猜你喜欢
        • 2014-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-03
        • 2018-01-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多