目录
查看CentOS版本、系统默认gcc版本、Python版本和pip版本
shell
cat /etc/redhat-release
shell
gcc --version
shell
python -V
shell
pip -V
部署Python-3.10.13
- 下载Python-3.10.13.tar.xz,Python官网:https://www.python.org/
- 安装编译依赖软件包及包组
shell
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel man
- 编译安装Python-3.10.13
shell
tar -xf Python-3.10.13.tar.xz -C /usr/src
shell
cd /usr/src/Python-3.10.13
shell
./configure --prefix=/usr/local/python-3.10.13 --enable-shared --enable-profiling --disable-ipv6 --with-pymalloc --with-doc-strings --enable-loadable-sqlite-extensions | tee /tmp/python-3.10.13.out
shell
less /tmp/python-3.10.13.out
shell
make -j 8
shell
make install
- 更改CentOS 7.9默认Python版本为3.10.13
shell
which python
shell
mv /usr/bin/python /usr/bin/python-2.7.5
ln -s /usr/local/python-3.10.13/bin/python3 /usr/bin/python
ln -s /usr/local/python-3.10.13/bin/pip3 /usr/bin/pip
- 添加至PATH环境变量
shell
# vim /etc/profile.d/python-3.10.13.sh
export PATH=/usr/local/python-3.10.13/bin:$PATH
shell
. /etc/profile.d/python-3.10.13.sh
echo $PATH
- 配置头文件
shell
ln -s /usr/local/python-3.10.13/include /usr/include/python-3.10.13
- 配置库文件
shell
echo "/usr/local/python-3.10.13/lib" > /etc/ld.so.conf.d/python-3.10.13.conf
cat /etc/ld.so.conf.d/python-3.10.13.conf
ldconfig
- 查看部署后的Python和pip版本
shell
python -V
python3 -V
pip -V
测试
shell
vim /tmp/test.py
python
#!/usr/bin/python
import os
# 获取操作系统类型
os_type = os.uname().sysname
print("操作系统类型:",os_type)
# 获取操作系统版本
os_version = os.uname().release
print("操作系统版本:",os_version)
# 获取主机名
hostname = os.uname().nodename
print("主机名:",hostname)
# 获取CPU信息
cpu_info = os.popen('cat /proc/cpuinfo | grep "model name"').read().strip()
print("CPU信息:")
print(cpu_info)
# 获取内存信息
mem_info = os.popen('cat /proc/meminfo | grep "MemTotal"').read().strip()
print("内存信息:")
print(mem_info)
# 获取磁盘使用情况
disk_usage = os.popen('df -h').read().strip()
print("磁盘使用情况:")
print(disk_usage)
# 获取/tmp目录下的文件信息
print("/tmp目录下的文件信息:")
os.system('ls -lh /tmp')
shell
python /tmp/test.py
将yum中的Python版本修改为系统原来的2.7.5版本
shell
# 将第一行的"#!/usr/bin/python"修改为"#!/usr/bin/python-2.7.5"
vim /usr/bin/yum
shell
# 将第一行的"#! /usr/bin/python"修改为"#! /usr/bin/python-2.7.5"
vim /usr/libexec/urlgrabber-ext-down