Dust8 的博客

读书百遍其义自见

0%

一键安装Python的shell脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash

# 一键安装Python

py_version=3.8.8
install_path=/usr/local

install_dependencies () {
# update the packages index
sudo apt-get update

# build dependencies
sudo apt-get build-dep python3 -y
sudo apt-get install pkg-config -y

# build all optional modules
# https://devguide.python.org/setup/#install-dependencies
sudo apt-get install -y build-essential gdb lcov pkg-config \
libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \
libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \
lzma lzma-dev tk-dev uuid-dev zlib1g-dev
}

install_python () {
# 国外源太慢, 可以用阿里源 https://registry.npmmirror.com/
# wget -c https://www.python.org/ftp/python/$py_version/Python-$py_version.tgz
wget -c https://registry.npmmirror.com/-/binary/python/$py_version/Python-$py_version.tgz

tar -xzf Python-$py_version.tgz -C /tmp

cd /tmp/Python-$py_version/

./configure --prefix=$install_path --enable-optimizations --with-ssl

make -j2

# 避免覆盖默认的python
sudo make altinstall
}

# http://c.biancheng.net/view/2991.html
read -p "请输入安装的python版本(例如: 3.8.8): " py_version
echo "python版本: $py_version"

install_dependencies;
install_python;

参考链接