centos安装python3
//
少说话,多做事
# Centos7-python3.6.8脚本升级
展开脚本
#!/bin/bash
ping -c 1 223.5.5.5 &>/dev/null
if [ $? -ne 0 ];then
echo "请检查网路"
exit 1
else
echo "正常网络"
fi
Path=$(cd $(dirname $0); pwd)
if [ -e ${Path}/Python-3.6.8.tgz ];then
echo "Python-3.6.8.tgz安装包已经存在"
else
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz -O ${Path}Python-3.6.8.tgz
fi
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel make gcc
if [ $? -ne 0 ];then
echo "依赖安装失败,请重试"
exit 1
fi
tar -xzvf ${Path}/Python-3.6.8.tgz -C /usr/local/
cd /usr/local/Python-3.6.8
./configure --prefix=/usr/local/python36
make -j $(nproc) && make install
if [ $? -ne 0 ];then
echo "编译失败,请检查"
exit 2
fi
#修改yum命令
mv /usr/bin/python /usr/bin/python-2.7.5 #改为你的老版本
sed -i 's#python#python2#g' /usr/bin/yum
sed -i 's#python#python2#g' /usr/libexec/urlgrabber-ext-down
ln -s /usr/local/python36/bin/python3.6 /usr/bin/python
test -f /usr/bin/pip || ln -s /usr/local/python36/bin/pip3 /usr/bin/pip
echo "export PATH=/usr/local/python36/bin:\$PATH" >> /etc/profile
echo "source /etc/profile" >> /root/.bashrc
source /etc/profile
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
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
# Ubuntu18.04
cd /opt
apt install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libncurses5-dev libsqlite3-dev libreadline-dev
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar xf Python-3.5.2.tgz
cd Python-3.5.2
./configure --prefix=/usr/local/python3
echo $?
make -j $(nproc)
echo $?
make install
echo 'export PATH=/usr/local/python3/bin:$PATH' >> /etc/profile
source /etc/profile
#检查
python3 -V
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# sqlite_scrapy模块安装
wget https://www.sqlite.org/2018/sqlite-autoconf-3250200.tar.gz
tar xf sqlite-autoconf-3250200.tar.gz && mv ./sqlite-autoconf-3250200 sqlite-autoconf
cd sqlite-autoconf/
./configure --prefix=/usr/local/sqlite3
make && make install
echo 'export PATH=/usr/local/sqlite3/lib:$PATH' >> /etc/profile
find / -name "setup.py" |xargs grep -rl "sqlite"
vim /root/soft/Python-3.6.8/setup.py
################################
#找sqlite,添加 '/usr/local/sqlite3/include',
sqlite_inc_paths = [ '/usr/include',
'/usr/include/sqlite',
'/usr/local/sqlite3/include',
'/usr/include/sqlite3',
'/usr/local/include',
'/usr/local/include/sqlite',
'/usr/local/include/sqlite3',
]
###########################
ln -s /usr/local/sqlite3/lib/* /usr/local/lib
ln -s /usr/local/sqlite3/lib/pkgconfig/sqlite3.pc /usr/local/lib/pkgconfig
cd /root/soft/Python-3.6.8/
make && make install
echo $?
#检查python 环境是否变成 2 了
重新 创造软链接 python3
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
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
# ffmpeg模块安装(Centos7)
ffmpeg.sh
ffmpeg-4.0.4.tar.bz2
yasm-1.1.0.tar.gz
1
2
3
2
3
# 个人存储下载地址。。。
python3.6.8.sh
Python-3.6.8.tgz
ffmpeg.sh
ffmpeg-4.0.4.tar.bz2
yasm-1.1.0.tar.gz
sqlite-autoconf-3250200.tar.gz
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
//
如果此文章对您有帮助,点击 -->> 请博主喝咖啡 (opens new window)
上次更新: 2023/11/20, 16:52:10