简体   繁体   English

RHEL6:将Python切换回原始默认版本

[英]RHEL6: Switch Python back to original default version

I am using RHEL6 which came with Python 2.6.6 pre-installed on it as the default python executable. 我正在使用预安装了Python 2.6.6的RHEL6作为默认python可执行文件。

Some months ago, I installed Python 2.7 on it and switched the default python version to 2.7 (yes, idiot move I now realize). 几个月前,我在上面安装了Python 2.7,并将默认的python版本切换到2.7(是的,我现在意识到是白痴的举动)。 So now when I type python it runs Python 2.7. 所以现在当我输入python它将运行Python 2.7。

Also: which python gives me /usr/local/bin/python 另外: which python给了我/usr/local/bin/python

As you might expect, and I only found out recently, this has caused issues when trying to run some system scripts which depend on the version being 2.6. 如您所料,我是最近才发现的,这在尝试运行某些依赖于2.6版本的系统脚本时引起了问题。 The 2.6 installation still exists and I can run it by either python2 or python2.6 . 2.6安装仍然存在,我可以通过python2python2.6运行它。

Also: which python2 gives /usr/bin/python2 and which python2.6 gives /usr/bin/python2.6 另外: which python2提供/usr/bin/python2和哪个python2.6提供/usr/bin/python2.6

The problem is that I do not remember how I switched the default version to 2.7. 问题是我不记得如何将默认版本切换到2.7。 I know I didn't create any alias, because I can't find any in the ~/.bashrc file. 我知道我没有创建任何别名,因为在~/.bashrc文件中找不到任何别名。

Does anyone have any advice on how I can revert back by changes so that Python 2.6.6 becomes the default once again? 是否有人对我如何通过更改还原回来有任何建议,以便Python 2.6.6再次成为默认设置? I can provide any further information that might be necessary to analyze this problem. 我可以提供分析此问题可能需要的任何其他信息。 Moreover, I have a couple of other people around me who are also using RHEL6 and haven't played around with their python installations, so if I need to copy any original scripts from /usr/bin/ to get this fixed I can get it from them, as long as I know what to get. 此外,我周围还有其他几个人也在使用RHEL6,但还没有玩过python的安装程序,因此,如果我需要从/usr/bin/复制任何原始脚本来修复此问题,我可以得到它从他们那里,只要我知道从中得到什么。

Thanks in advance for any advice! 在此先感谢您的任何建议!


Responses to Barun Sharma: 对Barun Sharma的回应:

Running ls -l /usr/local/bin/python* gives me: 运行ls -l /usr/local/bin/python*给我:

-rwxr-xr-x. 2 root root 6111394 Jan 16 2015 /usr/local/bin/python -rwxr-xr-x. 2 root root 6111394 Jan 16 2015 /usr/local/bin/python2.7 -rwxr-xr-x. 1 root root 1624 Jan 16 2015 /usr/local/bin/python2.7-config lrwxrwxrwx. 1 root root 9 Dec 26 2014 /usr/local/bin/python3 -> python3.4 -rwxr-xr-x. 2 root root 8777236 Dec 26 2014 /usr/local/bin/python3.4 lrwxrwxrwx. 1 root root 17 Dec 26 2014 /usr/local/bin/python3.4-config -> python3.4m-config -rwxr-xr-x. 2 root root 8777236 Dec 26 2014 /usr/local/bin/python3.4m -rwxr-xr-x. 1 root root 3013 Dec 26 2014 /usr/local/bin/python3.4m-config lrwxrwxrwx. 1 root root 16 Dec 26 2014 /usr/local/bin/python3-config -> python3.4-config lrwxrwxrwx. 1 root root 16 Jan 16 2015 /usr/local/bin/python-config -> python2.7-config

create a soft link:- 创建一个软链接:

ln -s /usr/bin/python2 /usr/local/bin/python 

Or directly point /usr/local/bin/python to your python2.6 binary(ie where ~/usr/bin/python2` points). 或者直接将/usr/local/bin/python指向您的python2.6二进制文件(即〜/ usr / bin / python2`指向的位置)。

Follow these steps:- 跟着这些步骤:-

1) rm /usr/local/bin/python . 1) rm /usr/local/bin/python This would remove the soft link. 这将删除软链接。 But python 2.7 will still be there. 但是python 2.7仍然存在。 You can check /usr/local/bin/python2.7 . 您可以检查/usr/local/bin/python2.7

2) ln -s /usr/local/bin/python2.6 /usr/local/bin/python . 2) ln -s /usr/local/bin/python2.6 /usr/local/bin/python Symbolic link from python to python2.6 从python到python2.6的符号链接

Also when you are working on python, I would advise you to use virtual environment and install your required python version and other packages. 另外,当您使用python时,我建议您使用virtual environment并安装所需的python版本和其他软件包。 I generally do not install packages to system python when it is required for a specific project(rather do it on a virtual env). 对于特定项目,我通常不将软件包安装到系统python中(而是在虚拟环境中进行安装)。

Once you have your system back to normal, the way to add new versions of Python 2.7, 3.3, or 3.4 to RHEL (6 or 7) is to utilize Software Collections (aka RHSCL or SCL) which install along side the original Python versions. 一旦系统恢复正常,向RHEL(6或7)添加Python 2.7、3.3或3.4的新版本的方法就是利用与原始Python版本一起安装的软件集合(aka RHSCL或SCL)。 There are many other languages, databases, web servers, and other tools, too. 还有许多其他语言,数据库,Web服务器和其他工具。 RHSCLs are included in most RHEL subscriptions. 大多数RHEL订阅中都包含RHSCL。

To get started: http://developers.redhat.com/products/softwarecollections/overview/ 开始使用: http : //developers.redhat.com/products/softwarecollections/overview/

You can also find information here: https://access.redhat.com/products/Red_Hat_Enterprise_Linux/Developer/#rhscl=&dev-page=5 您也可以在这里找到信息: https : //access.redhat.com/products/Red_Hat_Enterprise_Linux/Developer/#rhscl=&dev-page=5

OR here: http://developerblog.redhat.com/tag/software-collections/ 或者在这里: http : //developerblog.redhat.com/tag/software-collections/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM