|
| 1 | +# Installing Python 2.7 on Centos 6.5 |
| 2 | + |
| 3 | +Centos 6.\* comes with Python 2.6, but we can't just replace it with v2.7 because it's used by the OS internally (apparently) so you will need to install v2.7 (or 3.x, for that matter) along with it. Fortunately, CentOS made this quite painless with their [Software Collections Repository](http://wiki.centos.org/AdditionalResources/Repositories/SCL) |
| 4 | + |
| 5 | +```bash |
| 6 | +# yum update # update yum |
| 7 | +# yum install centos-release-scl # install SCL |
| 8 | +# yum install python27 # install Python 2.7 |
| 9 | +# /opt/rh/python27/root/usr/bin/python2.7 -V |
| 10 | +/opt/rh/python27/root/usr/bin/python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory |
| 11 | +``` |
| 12 | +
|
| 13 | +To make 2.7 work, config `/etc/ld.so.conf.d/python27.conf`: |
| 14 | +
|
| 15 | +```bash |
| 16 | +# /sbin/ldconfig -v |grep python |
| 17 | +/sbin/ldconfig: /etc/ld.so.conf.d/kernel-2.6.32-642.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg |
| 18 | +/sbin/ldconfig: Path `/lib' given more than once |
| 19 | +/sbin/ldconfig: Path `/usr/lib' given more than once |
| 20 | + libpyglib-2.0-python.so.0 -> libpyglib-2.0-python.so.0.0.0 |
| 21 | + libpython2.6.so.1.0 -> libpython2.6.so.1.0 |
| 22 | +# find / -name libpython2.7.so.1.0 |
| 23 | +/opt/rh/python27/root/usr/lib64/libpython2.7.so.1.0 |
| 24 | +# echo '/opt/rh/python27/root/usr/lib64/' > /etc/ld.so.conf.d/python27.conf |
| 25 | +# /sbin/ldconfig -v |grep python |
| 26 | +/sbin/ldconfig: /etc/ld.so.conf.d/kernel-2.6.32-642.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg |
| 27 | +/sbin/ldconfig: Path `/lib' given more than once |
| 28 | +/sbin/ldconfig: Path `/usr/lib' given more than once |
| 29 | +/opt/rh/python27/root/usr/lib64: |
| 30 | + libpython2.7.so.1.0 -> libpython2.7.so.1.0 |
| 31 | + libpyglib-2.0-python.so.0 -> libpyglib-2.0-python.so.0.0.0 |
| 32 | + libpython2.6.so.1.0 -> libpython2.6.so.1.0 |
| 33 | +/opt/rh/python27/root/usr/lib64/tls: (hwcap: 0x8000000000000000) |
| 34 | +/opt/rh/python27/root/usr/lib64/sse2: (hwcap: 0x0000000004000000) |
| 35 | +# /opt/rh/python27/root/usr/bin/python2.7 -V |
| 36 | +Python 2.7.13 |
| 37 | +``` |
| 38 | +
|
| 39 | +To install additional libraries, you will need to install PIP: |
| 40 | +
|
| 41 | +```bash |
| 42 | +# wget https://bootstrap.pypa.io/get-pip.py |
| 43 | +# /opt/rh/python27/root/usr/bin/python2.7 get-pip.py |
| 44 | +``` |
| 45 | +
|
| 46 | +once installed, you can install PIP using `pip2.7`, e.g.: |
| 47 | +
|
| 48 | +```bash |
| 49 | +# pip2.7 install requests |
| 50 | +# /opt/rh/python27/root/usr/bin/pip -V |
| 51 | +pip 18.0 from /opt/rh/python27/root/usr/lib/python2.7/site-packages/pip (python 2.7) |
| 52 | +``` |
| 53 | +
|
| 54 | +(Hack)Add in `~/.bash_profile` or `~/.zshrc` |
| 55 | +
|
| 56 | +```bash |
| 57 | +alias python=/opt/rh/python27/root/usr/bin/python |
| 58 | +alias pip=/opt/rh/python27/root/usr/bin/pip |
| 59 | +export PATH=/opt/rh/python27/root/usr/bin:$PATH |
| 60 | +``` |
| 61 | +
|
| 62 | +`pip install -U pip # Update pip` |
| 63 | + |
| 64 | +## Reference |
| 65 | + |
| 66 | +- [Installing Python 2.7 on Centos 6.5](https://gist.github.com/dalegaspi/dec44117fa5e7597a559) |
| 67 | +- [CentOS6系统安装Python2.7](https://www.jianshu.com/p/b8792a7b5350) |
0 commit comments