一键安装python3环境

一键安装python3环境

由于现在逐步转移到 python3 进行开发,但是很多机器并没有预装 python3 环境,所以需要安装。

所以分享一个我常用的,一键安装 python3.7 的脚本:

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
#!/bin/sh

which python3
if [ $? -eq 1 ]
then
echo "no python3 found, will try to install python3"
yum -y install wget &&
yum -y groupinstall "Development tools" &&
yum -y install zlib-devel libffi-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel &&
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz &&
mkdir /opt/python3 &&
tar -xvJf Python-3.7.2.tar.xz &&
cd Python-3.7.2 &&
./configure --prefix=/opt/python3 &&
make &&
make install
cd -

ln -s /opt/python3/bin/python3 /usr/bin/python37
ln -s /opt/python3/bin/pip3 /usr/bin/pip3
yum -y install epel-release &&
yum -y install python-pip
ln -s /usr/bin/python37 /usr/bin/python3

yum install -y python-virtualenv.noarch

rm -rf Python-3.7.2*
else
echo 'check python3 ################################## Yes'
fi

脚本会探测环境是否已经安装了 python3,如果没有安装则进行安装。

同时也把 virtualenv 工具安装了。

脚本可以直接在 我的github 进行下载。

其他

欢迎关注下我的其他脚本,平常可能会用到的一些脚本,整理了一下。

https://github.com/smaugx/dailytools

Blog:

2018-04-15 于杭州
By 史矛革

buy me a cola!

欢迎关注我的其它发布渠道