天天看點

Python 編譯安裝 IP103.107.191.Xxx​

Python 編譯安裝 IP103.107.191.Xxx​

安裝步驟 103.107.191.Xxx​

# 安裝依賴​

yum -y install zlib zlib-devel bzip2-devel libffi-devel openssl-devel sqlite-devel​

# 下載下傳包​

wget https://npm.taobao.org/mirrors/python/3.8.6/Python-3.8.6.tgz​

# 解壓​

tar xzvf Python-3.8.6.tgz​

# 編譯cd Python-3.8.6 && ./configure --prefix=/usr/local/python/3.8.6​

# make altinstall不會建立軟鍊和手冊相關資訊​

make && make altinstall​

# 驗證​

python -V​

腳本​

#!/bin/bash​

# 适用于騰訊雲 centos 7.8# cat /etc/redhat-release# check packagesif [[ $(yum list installed | grep openssl-devel1) == "" ]]; then​

echo "\"openssl-devel\" not found, u can install by \`yum -y install zlib zlib-devel bzip2-devel libffi-devel openssl-devel sqlite-devel\`"​

exit 1else​

echo "required package found"fi​

# check argument# https://stackoverflow.com/questions/6482377/check-existence-of-input-argument-in-a-bash-shell-scriptif [ -z "$1" ]; then​

echo "not version specify."​

exit 1fi​

version=$1​

index_url="https://npm.taobao.org/mirrors/python"​

file_name="Python-$version.tgz"​

download_url="$index_url/$version/$file_name"​

operate_folder="/tmp"​

save_path="$operate_folder/$file_name"​

extra_path="$operate_folder/Python-$version"​

configure_prefix="/usr/local/python/$version"​

# re & endswith:# https://codingstandards.iteye.com/blog/1187353# https://stackoverflow.com/questions/21112707/check-if-a-string-matches-a-regex-in-bash-script# get curl status code:# https://superuser.com/questions/272265/getting-curl-to-output-http-status-code# https://stackoverflow.com/questions/38905489/how-to-check-if-the-curl-was-successful-and-print-a-message# status_code=$(curl -s -o /dev/null -I -w "%{http_code}" $index_url)​

resp=$(curl --silent --max-time 15 --write-out "%{http_code}" $index_url)if !([[ $resp =~ $version ]] && [[ $resp == *200 ]]); then​

# echo $resp​

echo "version: $version not found in: \"$index_url\""​

exit 1fi​

# promt# https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script# case# https://www.shellscript.sh/case.htmlecho "version: $version founded"read -p "Are you sure to download? y/Y to continue" -n 1 -recho # (optional) move to a new lineif !([[ $REPLY =~ ^[Yy]$ ]]); then​

exit 0fi​

# test file exists# https://stackoverflow.com/questions/40082346/how-to-check-if-a-file-exists-in-a-shell-scriptif [ -e $save_path ]; then​

echo "file exitst"else​

echo "dowloading..."​

wget -O $save_path $download_url​

echo "download complete"fi​

echo "extracting..."​

tar -xzvf $save_path --directory $operate_folderecho "extract complete"​

cd $extra_path && ./configure --prefix=$configure_prefix && make && make altinstall && rm -rf $extra_path​

exit 0​

折疊​

軟連結​

ln -s /usr/local/python/3.8.6/bin/pipenv /usr/local/bin/pipenvln -s /usr/local/python/3.8.6/bin/pip3 /usr/local/bin/pip3ln -s /usr/local/python/3.8.6/bin/python3.8 /usr/local/bin/python3​

pip 加速和鏡像​

# 臨時​

pip3 install -i https://mirrors.cloud.tencent.com/pypi/simple <some-package>​

# 設為預設​

pip3 install pip -U​

pip3 config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple​

# 更新pip​

pip3 install --upgrade pip -i https://mirrors.cloud.tencent.com/pypi/simple/​

pip 鏡像源​

馳網​

https://idc02.com​

​​https://pypi.douban.com/simple​​​

安裝​

# 安裝 pipenv​

pip3 install pipenv -i https://mirrors.cloud.tencent.com/pypi/simple/​

pipenv 生成虛拟環境​

mkdir test && cd test​

# pipenv install --python /usr/local/python/...​

pipenv install --python python3​