指定开发环境所在的目录,这里为/usr/local/src/python_develop
指定Python的版本,这里为3.5.2
#!/bin/bash
#
DEVELOP_DIR="/usr/local/src/python_develop"
PYTHON_VER=3.5.2
cd /usr/local/src
# install depend on
yum install -y zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel git > /dev/null
# install pyenv
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash > /dev/null
# install pip
wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
python get-pip.py > /dev/null
# configuration pyenv
cat > /etc/profile.d/pyenv.sh << EOF
export PATH=/root/.pyenv/bin:\${PATH}
EOF
source /etc/profile.d/pyenv.sh
# Configure the shell environment for pyenv
cat >> ~/.bash_profile << EOF
export PYENV_ROOT=/root/.pyenv
if which pyenv > /dev/null; then
eval "\$(pyenv init -)"
eval "\$(pyenv virtualenv-init -)"
fi
EOF
bash ~/.bash_profile
# install python
[ ! -d ${DEVELOP_DIR} ] && mkdir -p ${DEVELOP_DIR} && cd ${DEVELOP_DIR}
pyenv install ${PYTHON_VER} > /dev/null
# setting pip download source
[ ! -d ~/.pip ] && mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
EOF
到对应主机上bash执行即可
依赖包问题
1.依赖包的安装
yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel git
2. configure: error: no acceptable C compiler found in $PATH
yum install gcc
3. Build failed: "ERROR: The Python zlib extension was not compiled. Missing the zlib?"
CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install -v 2.7.6
4. /root/.pyenv/plugins/python-build/bin/python-build: line 1326: patch: command not found
yum install patch