有勇气的牛排博客

Centos安装 Python

有勇气的牛排 530 Python 2022-12-29 23:10:28

1 安装

1.1 安装依赖

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel

yum install gcc gcc-c++ openssl-devel libffi-devel tk-devel

1.2 下载、解压

mkdir -p /usr/local/python3
cd /usr/local/python3
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
xz -d Python-3.8.5.tar.xz
tar -xvf Python-3.8.5.tar
cd Python-3.8.5

1.3 安装

授权(谨慎操作)

sudo chmod -R 777 /usr/local/python3/Python-3.8.5
./configure --prefix=/usr/local/python3/Python-3.8.5_build
make && make install
# 如果您想要一个具有所有稳定优化活动(PGO 等)的发布版本,请运行 
./configure --enable-optimizations

python3.8 解释器位置,一般是 /usr/local/bin/python3.8

删除原来的软连接

rm -rf /usr/bin/python3.8
rm -rf /usr/bin/pip3.8

添加python3与pip3的软链接

ln -s /usr/local/python3/Python-3.8.5_build/bin/python3.8 /usr/bin/python3.8
ln -s /usr/local/python3/Python-3.8.5_build/bin/pip3.8 /usr/bin/pip3.8

验证

python3.8 -V
pip3.8 -V

2 报错处理

WARNING: The directory ‘/home/ubuntu/.cache/pip’ or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag

sudo chown -R ubuntu/home/ubuntu/.cache/pip/
sudo chown -R ubuntu/home/ubuntu/.cache/pip/http/

sudo chown -R ubuntu /home/ubuntu/.cache/pip/
sudo chown -R ubuntu /home/ubuntu/.cache/pip/http

sudo find / -name 'lsb_release.py'
sudo cp  /usr/share/pyshared/lsb_release.py /usr/local/soft/python3/lib/python3.7/

作者:有勇气的牛排


留言

专栏
文章
加入群聊