from:https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/
for ubuntu: https://askubuntu.com/questions/981118/correct-way-to-install-python-2-7-on-ubuntu-17-10/981279
准备
# Start by making sure your system is up-to-date: yum update # Compilers and related tools: yum groupinstall -y "development tools" # Libraries needed during compilation to enable all features of Python: yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel # If you are on a clean "minimal" install of CentOS you also need the wget tool: yum install -y wget
安装:
# Python 2.7.14: wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz tar xf Python-2.7.14.tar.xz cd Python-2.7.14 ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" make && make altinstall
# error while loading shared libraries: libpython2.7.so.1.0
ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/lib # link libpython2.7.so to /usr/lib/libpython2.7.so
ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib
ln -s /usr/local/python2.7/bin/python2.7 /usr/local/bin
# add /usr/local/bin, /usr/lib in /etc/ld.so.conf, 2 lines, just directory is enough
/sbin/ldconfig -v
# Python 3.6.3:
wget http://python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar xf Python-3.6.3.tar.xz cd Python-3.6.3
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
安装pip
# First get the script: wget https://bootstrap.pypa.io/get-pip.py # Then execute it using Python 2.7 and/or Python 3.6: python2.7 get-pip.py python3.6 get-pip.py # With pip installed you can now do things like this: pip2.7 install [packagename] pip2.7 install --upgrade [packagename] pip2.7 uninstall [packagename]
使用官方离线包安装,
cd setuptools
python2.7 setup.py install
cd pip
python2.7 setup.py install