Python 编译安装 IP103.107.191.Xxx​
  8LR53G7AJDoV 2023年11月02日 90 0

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


sed -i "s/pypi.org/mirrors.cloud.tencent.com\/pypi/g" Pipfile


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
8LR53G7AJDoV
最新推荐 更多