centos6.8/ubuntu 安装python2.7 or python3.6

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

for macos: https://devguide.python.org/setup/#macos-and-os-x%20for%20more%20information

brew install: https://apple.stackexchange.com/questions/237430/how-to-install-specific-version-of-python-on-os-x

准备# 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

#ubuntu
sudo apt-get install -y gcc make build-essential libssl-dev zlib1g-dev
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev

安装:

# 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" --with-ssl --enable-optimizations
make && make altinstall

# for mac os
brew install pyenv pyenv install 3.6.10

 安装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]
# python3.6 pip默认安装
python3.6 -m pip install [Package_to_install]

使用官方离线包安装,
cd setuptools
python2.7 setup.py install
cd pip
python2.7 setup.py install
原文地址:https://www.cnblogs.com/buxizhizhoum/p/8117984.html