red hat怎么升级python

red hat怎么升级python,第1张

从今天开始学习Python!看了一下虚拟机RedHat中的python,发现还是原生的2.4.3,所以决定升级一下

[root@linuxidc ~]# python

Python 2.4.3 (#1, May 5 2011, 16:39:10)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

[root@linuxidc ~]#

1.下载z最新版本的python

[root@linuxidc ~]# wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz

2.解压及编译

[root@linuxidc ~]# tar xvf Python-2.7.2.tar.bz2

[root@linuxidc Python-2.7.6]# ./configure --prefix=/usr/local/python27

[root@linuxidc Python-2.7.6]# make

[root@linuxidc Python-2.7.6]# make install

[root@linuxidc Python-2.7.6]# ls /usr/local/python27/ -al

total 28

drwxr-xr-x 6 root root 4096 Mar 21 01:01 .

drwxr-xr-x 13 root root 4096 Mar 21 01:01 ..

drwxr-xr-x 2 root root 4096 Mar 21 01:01 bin

drwxr-xr-x 3 root root 4096 Mar 21 01:01 include

drwxr-xr-x 4 root root 4096 Mar 21 01:01 lib

drwxr-xr-x 3 root root 4096 Mar 21 01:01 share

3.覆盖原有的python链接

[root@linuxidc Python-2.7.6]# mv /usr/bin/python /usr/bin/python_old

[root@linuxidc Python-2.7.6]# ln -s /usr/local/python27/bin/python /usr/bin/

[root@linuxidc Python-2.7.6]# python

Python 2.7.6 (default, Mar 21 2014, 01:00:09)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

此时已经可以正常使用python2.7了,但是因为yum是使用的2.4的版本来用的,现在输入一下yum就会报错

[root@linuxidc Python-2.7.6]# yum

There was a problem importing one of the Python modules

required to run yum. The error leading to this problem was:

No module named yum

Please install a package which provides this module, or

verify that the module is installed correctly.

It's possible that the above module doesn't match the

current version of Python, which is:

2.7.6 (default, Mar 21 2014, 01:00:09)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)]

If you cannot solve this problem yourself, please go to

the yum faq at:

http://wiki.linux.duke.edu/YumFaq

5.修改yum

[root@linuxidc Python-2.7.6]# vim /usr/bin/yum

#!/usr/bin/python #修改此处为2.4的位置

[root@linuxidc Python-2.7.6]# vim /usr/bin/yum

#!/usr/bin/python2.4

yum 可以使用了!

[root@linuxidc Python-2.7.6]# yum

Loaded plugins: rhnplugin, security

You need to give some command

usage: yum [options] COMMAND

List of Commands:

check-update Check for available package updates

clean Remove cached data

deplistList a package's dependencies

erase Remove a package or packages from your system

groupinfo Display details about a package group

groupinstall Install the packages in a group on your system

grouplist List available package groups

groupremoveRemove the packages in a group from your system

help Display a helpful usage message

info Display details about a package or group of packages

info-security Returns security data for the packages listed, that affects your system

installInstall a package or packages on your system

list List a package or groups of packages

list-security Returns security data for the packages listed, that affects your system

localinstall Install a local RPM

makecache Generate the metadata cache

provides Find what package provides the given value

reinstall reinstall a package

repolist Display the configured software repositories

resolvedepDetermine which package provides the given dependency

searchSearch package details for the given string

shell Run an interactive yum shell

updateUpdate a package or packages on your system

update-minimal Works like update, but goes to the 'newest' package match which fixes a problem that affects your system

upgradeUpdate packages taking obsoletes into account

options:

-h, --helpshow this help message and exit

-t, --tolerantbe tolerant of errors

-Crun entirely from cache, don't update cache

-c [config file]config file location

-R [minutes]maximum command wait time

-d [debug level]debugging output level

--showduplicates show duplicates, in repos, in list/search commands

-e [error level]error output level

-q, --quiet quiet operation

-v, --verboseverbose operation

-yanswer yes for all questions

--versionshow Yum version and exit

--installroot=[path] set install root

--enablerepo=[repo] enable one or more repositories (wildcards allowed)

--disablerepo=[repo] disable one or more repositories (wildcards allowed)

-x [package], --exclude=[package]

exclude package(s) by name or glob

--disableexcludes=[repo]

disable exclude from main, for a repo or for

everything

--obsoletes enable obsoletes processing during updates

--noplugins disable Yum plugins

--nogpgcheck disable gpg signature checking

--disableplugin=[plugin]

disable plugins by name

--enableplugin=[plugin]

enable plugins by name

--skip-brokenskip packages with depsolving problems

--securityInclude security relevant packages

--cve=CVEInclude packages needed to fix the given CVE

--bz=BZ Include packages needed to fix the given BZ

--advisory=ADVISORY Include packages needed to fix the given advisory

[root@linuxidc Python-2.7.6]#

在ubuntu 的终端中用代码下载最新的Python

sudo apt-get install python3

系统会提示输入Linux 的密码,输入密码后下载 

刚才下载的Python程序被安装在usr/local/lib/python3.5 中

用命令删除usr/bin/目录下的默认python link文

系统默认python编译器建立新的连接

sudo ln -s /usr/bin/python3.5 /usr/bin/python

验证系统默认Python是否是刚才安装的

直接在命令窗口输入python即可

在python版本安装好后,需要执行如下类似命令,更改系统默认python路径,如 ln -fs /usr/local/python2.7/bin/python2.7 /usr/bin/python 更改系统默认python版本为python2.7

关于更多Linux的学习,请查阅书籍《linux就该这么学》。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7679691.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-08
下一篇 2023-04-08

发表评论

登录后才能评论

评论列表(0条)

保存