指定開發環境所在的目錄,這裏爲/usr/local/src/python_developpython
指定Python的版本,這裏爲3.5.2git
#!/bin/bash
#
DEVELOP_DIR="/usr/local/src/python_develop"
PYTHON_VER=3.5.2github
cd /usr/local/srcsql
# install depend on
yum install -y zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel git > /dev/nullshell
# install pyenv
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash > /dev/nullbootstrap
# install pip
wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
python get-pip.py > /dev/nullbash
# configuration pyenv
cat > /etc/profile.d/pyenv.sh << EOF
export PATH=/root/.pyenv/bin:\${PATH}
EOFcurl
source /etc/profile.d/pyenv.shui
# 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
EOFurl
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