首页 / PYTHON / Python 编译安装
Python 编译安装
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python 编译安装,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3556字,纯文字阅读大概需要6分钟。
内容图文
![Python 编译安装](/upload/InfoBanner/zyjiaocheng/621/b5a836e4af3c4aa7a5e9e751db4492a6.jpg)
安装
安装步骤
# 安装依赖
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 packages
if [[ $(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 1
else
echo "required package found"
fi
# check argument
# https://stackoverflow.com/questions/6482377/check-existence-of-input-argument-in-a-bash-shell-script
if [ -z "$1" ]; then
echo "not version specify."
exit 1
fi
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 1
fi
# promt
# https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script
# case
# https://www.shellscript.sh/case.html
echo "version: $version founded"
read -p "Are you sure to download? y/Y to continue" -n 1 -r
echo # (optional) move to a new line
if !([[ $REPLY =~ ^[Yy]$ ]]); then
exit 0
fi
# test file exists
# https://stackoverflow.com/questions/40082346/how-to-check-if-a-file-exists-in-a-shell-script
if [ -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_folder
echo "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/pipenv
ln -s /usr/local/python/3.8.6/bin/pip3 /usr/local/bin/pip3
ln -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://mirrors.cloud.tencent.com/pypi/simple
豆瓣:
https://pypi.douban.com/simple
安装 pipenv
# 安装 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
内容总结
以上是互联网集市为您收集整理的Python 编译安装全部内容,希望文章能够帮你解决Python 编译安装所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。