无法在Red Hat Linux上升级Python
我在我的Red Hat Linux虚拟机上用的是Python 2.6.6来运行一个特定的脚本。现在我需要升级到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删掉,因为很多系统脚本都依赖它。有没有什么建议可以帮我解决这个问题?
3 个回答
红帽公司提供了多个版本的Python(还有其他软件包),这些版本可以并行安装,作为软件集合的一部分。这样做的好处是可以保持系统的/usr/bin/目录不变,并且这些版本是由红帽公司支持的。
你需要做的是:
* 启用RHSCL和可选的软件仓库
* 然后你可以用 yum install rh-python36
或 python27
(2.7.13)来安装
* 使用 scl enable rh-python36 bash
来把Python添加到你的路径中。
可以查看 如何在RHEL上安装Python 3。这篇文章提供了很多关于如何使用多个版本的Python、Python虚拟环境和软件集合的技巧。
我一般不建议在像RHEL这样的RPM管理的系统上手动升级软件包。如果需要升级,最好通过rpm工具来进行。使用rpm工具是有原因的,实际上有很多原因。它有着重要的作用,而手动安装或升级软件包会完全破坏这个作用。
如果真的必须手动升级,可以按照以下步骤进行:
- 先获取Red Hat的python软件包的源RPM。
- 然后获取新版本的python源代码。
- 找出Red Hat的python RPM中有哪些补丁仍然适用于新版本的python(如果有的话)。
- 使用python RPM中的规格文件来构建带有新版本python的rpm包。
- 希望第4步能成功。如果成功了,太好了!就安装它。如果不成功,找出原因,必要时修补规格文件,然后回到第4步。
- 现在你已经安装了新版本的python。检查一下其他使用python的RHEL rpm包是否在新版本下出现问题。如果没有,太好了!你完成了。如果有问题,想办法解决它。
很多RHEL系统管理工具和脚本都是用Python写的。因此,安装新python包后,某些东西可能会出现问题,这并不是不可能的。
使用RHEL的原因就是为了拥有一个商业支持的、稳定的Linux系统,所有组件都经过了互操作性测试。随意升级其中的某些部分就失去了使用RHEL的意义;通常情况下,你是升级整个RHEL的新版本,而不是单独的包;不过,每个人有自己的做法……
你需要找到Python-3.4的安装包来源,或者自己动手编译。
快速搜索一下可以找到一个链接,教你怎么自己编译Python-3.4,地址是http://wiki.guibin.info/?p=133。
如果再多找找,你可能会找到RPM包的来源,但当然了,使用这些包的安全性就得看你自己怎么判断了——我可不建议在正式环境中随便用一个不熟悉的RPM包!