编译安装python3.8的步骤
1.下载python3源码包
wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz
2.下载python3编译的依赖包
yum install -y gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
3.解压缩源码包
tar -zxvf Python-3.8.3.tgz
4.进入源码包文件夹
cd Python-3.8.3
5.编译且安装
进入源码包目录
ls查看源码包内容
释放编译文件 Makefile
./configure --prefix=/opt/python38 # 指定安装目录为/opt/python38
4.编译
make # 相当于把源码包里面的代码编译成linux服务器可以识别的代码
5.编译安装,此步才会最终生成 /opt/python38/
make install
注意: 第4步和第5步可以合并执行, 但是中间需要用&&隔开
make && make install # 先进行make,执行完成之后,才开始执行make install
进入/opt目录查看python38文件夹,我们要的python3都在这里了
/opt/python38/bin/python3
/opt/python38/bin/pip3
.....
6.更改linux的path变量,添加python3
修改/etc/profile系统环境变量配置文件,添加以下内容
vi /etc/profile # 系统环境变量配置文件
export PYTHON_HOME=/opt/python38
export PATH=$PATH:$PYTHON_HOME/bin
source /etc/profile
更换pip源
1)检查pip.conf文件是否存在
>> cd ~
>> mkdir .pip
>> ls ~/.pip
2)直接编辑pip.conf
sudo vi ~/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
pip3 install scrapy
pip3 install scrapy-redis
pip3 install beautifulsoup4
注意:本文归作者所有,未经作者允许,不得转载