[root@qsh ~]# cat /etc/centos-release CentOS Linux release 7.6.1810 (Core)
[root@qsh ~]# python -V Python 2.7.5 [root@qsh usr]# ll -l /usr/bin/python* lrwxrwxrwx 1 root root 7 3月 29 22:44 /usr/bin/python -> python2 lrwxrwxrwx 1 root root 9 3月 29 22:44 /usr/bin/python2 -> python2.7 -rwxr-xr-x 1 root root 7136 11月 6 00:29 /usr/bin/python2.7
[root@qsh packages]# wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz [root@qsh packages]# tar zxvf Python-2.7.15.tgz
yum install gcc* openssl openssl-devel ncurses-devel.x86_64 bzip2-devel sqlite-devel python-devel zlib
cd Python-2.7.15 ./configure --prefix=/usr/local # [配置]指定可執行文件、庫文件、配置文件、資源文件的安裝路徑。若沒有權限加sudo make # 編譯 make altinstall # 不要使用make install,不然會覆蓋系統自帶python
[root@qsh ~]# python -V # 發現版本仍是原版本Python 2.7.5
[root@qsh ~]# ll -l /usr/bin/python* # 系統自帶的 lrwxrwxrwx 1 root root 7 2019/03/03 14:24:13 /usr/bin/python -> python2 lrwxrwxrwx 1 root root 9 2019/03/03 14:24:13 /usr/bin/python2 -> python2.7 -rwxr-xr-x 1 root root 7216 2018/10/31 07:46:45 /usr/bin/python2.7 -rwxr-xr-x 1 root root 1835 2018/10/31 07:46:26 /usr/bin/python2.7-config lrwxrwxrwx 1 root root 16 2019/03/26 17:13:24 /usr/bin/python2-config -> python2.7-config lrwxrwxrwx 1 root root 14 2019/03/26 17:13:24 /usr/bin/python-config -> python2-config [root@qsh ~]# ll -l /usr/local/bin/python* # 手工安裝的 -rwxr-xr-x 1 root root 8296384 2019/03/26 17:16:56 /usr/local/bin/python2.7 -rwxr-xr-x 1 root root 1687 2019/03/26 17:17:05 /usr/local/bin/python2.7-config
[root@qsh ~]# mv /usr/bin/python /usr/bin/python2.7.5 [root@qsh ~]# ll -l /usr/bin/python* lrwxrwxrwx 1 root root 9 2019/03/03 14:24:13 /usr/bin/python2 -> python2.7 -rwxr-xr-x 1 root root 7216 2018/10/31 07:46:45 /usr/bin/python2.7 lrwxrwxrwx 1 root root 7 2019/03/03 14:24:13 /usr/bin/python2.7.5 -> python2 # 改成2.7.5 -rwxr-xr-x 1 root root 1835 2018/10/31 07:46:26 /usr/bin/python2.7-config lrwxrwxrwx 1 root root 16 2019/03/26 17:13:24 /usr/bin/python2-config -> python2.7-config lrwxrwxrwx 1 root root 14 2019/03/26 17:13:24 /usr/bin/python-config -> python2-config [root@qsh ~]# ln -s /usr/local/bin/python2.7 /usr/bin/python # 增長鏈接 [root@qsh ~]# ll -l /usr/bin/python* lrwxrwxrwx 1 root root 24 2019/03/26 17:20:18 /usr/bin/python -> /usr/local/bin/python2.7 # 新增的,並指向新安裝的python lrwxrwxrwx 1 root root 9 2019/03/03 14:24:13 /usr/bin/python2 -> python2.7 -rwxr-xr-x 1 root root 7216 2018/10/31 07:46:45 /usr/bin/python2.7 lrwxrwxrwx 1 root root 7 2019/03/03 14:24:13 /usr/bin/python2.7.5 -> python2 -rwxr-xr-x 1 root root 1835 2018/10/31 07:46:26 /usr/bin/python2.7-config lrwxrwxrwx 1 root root 16 2019/03/26 17:13:24 /usr/bin/python2-config -> python2.7-config lrwxrwxrwx 1 root root 14 2019/03/26 17:13:24 /usr/bin/python-config -> python2-config
[root@qsh ~]# python -V Python 2.7.15
[root@qsh ~]# python2.7.5 -V Python 2.7.5
[root@qsh ~]# yum -y install epel-release 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.13 (default, Apr 2 2017, 04:48:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq #解決方法 [root@qsh ~]# vi /usr/bin/yum 首行的#!/usr/bin/python 改成 #!/usr/bin/python2.7 改完以後繼續安裝,又報錯... ImportError: No module named urlgrabber.grabber [root@qsh ~]# vi /usr/libexec/urlgrabber-ext-down 首行的#!/usr/bin/python 改成 #!/usr/bin/python2.7
1. 下載安裝php
wget https://bootstrap.pypa.io/get-pip.py python get-pip.py
2. 設置軟鏈接html
ln -s /usr/local/bin/pip2.7 /usr/bin/pip2 ln -s /usr/local/bin/pip2.7 /usr/bin/pip2.7
#安裝 ipythonpython
pip install ipython==1.2.1 ln -s /usr/local/python27/bin/ipython /usr/bin/ipython