Linux CentOS 6.7上安装Python 2.7.12

CentOS 6.6自带的是Python 2.6.6,而编译llvm需要Python 2.7以上。

checking for python...

which python

 /usr/bin/python

python -V

Python 2.6.6

yum中最新的也是Python 2.6.6,只能下载Python 2.7.12的源代码自己编译安装。

操作步骤如下:

1)安装devtoolset

yum groupinstall "Development tools"

2)安装编译Python需要的包包

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

3)下载并解压Python 2.7.12的源代码

cd /opt

wget --no-check-certificate https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz

wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz

#如果tar版本过低,请使用xz -d xx.tar.xz 然后 tar -xf xxx.tar

tar -xvf Python-2.7.12.tar.xz

cd Python-2.7.12

4)编译与安装Python 2.7.12

./configure --prefix=/opt/python27

make && make altinstall

5)将python命令指向Python 2.7.12

#备份老python

mv /usr/bin/python /usr/bin/python2.6.6

#建立软连接

ln -s /opt/python27/bin/python2.7 /usr/bin/python

升级python以后yum的使用可能会受到影响,需要进行一下设置

vi /usr/bin/yum

找到第一行 #!/usr/bin/python 改为 #!/usr/bin/python2.6.6

至此升级完成!

6)检查Python版本

python -V

Python 2.7.12



make install 的几种情况



Let's take a look at the generated Makefile!

First, the install target:

install:        altinstall bininstall maninstall

It does everythingaltinstalldoes, along withbininstallandmaninstall

Here'sbininstall, it just creates thepythonand other symbolic links.

# Install the interpreter by creating a symlink chain:

#  $(PYTHON) -> python2 -> python$(VERSION))

# Also create equivalent chains for other installed files

bininstall:    altbininstall

-if test -f $(DESTDIR)$(BINDIR)/$(PYTHON) -o -h $(DESTDIR)$(BINDIR)/$(PYTHON); \

then rm -f $(DESTDIR)$(BINDIR)/$(PYTHON); \

else true; \

fi

(cd $(DESTDIR)$(BINDIR); $(LN) -s python2$(EXE) $(PYTHON))

-rm -f $(DESTDIR)$(BINDIR)/python2$(EXE)

(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(EXE) python2$(EXE))

... (More links created)

And here'smaninstall, it just creates "unversioned" links to the python manual pages.

# Install the unversioned manual pages

maninstall:    altmaninstall

-rm -f $(DESTDIR)$(MANDIR)/man1/python2.1

(cd $(DESTDIR)$(MANDIR)/man1; $(LN) -s python$(VERSION).1 python2.1)

-rm -f $(DESTDIR)$(MANDIR)/man1/python.1

(cd $(DESTDIR)$(MANDIR)/man1; $(LN) -s python2.1 python.1)

Tl;dr:altinstallskips creating thepythonlink and the manual pages links,installwill hide the system binaries and manual pages.

你可能感兴趣的:(Linux CentOS 6.7上安装Python 2.7.12)