安装依赖文件:
查看gcc编译器:
[root@VM-16-13-centos]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-15) (GCC)
若不存在:执行安装命令
yum -y install gcc
一个相关依赖:
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 libffi-devel
注意:我的腾讯云服务器会发生报错,此时需要去掉 db4-devel libpcap-devel 命令即可
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel xz-devel libffi-devel
下载python安装包
官方下载,速度较慢
wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
淘宝下载,速度快
wget http://npm.taobao.org/mirrors/python/3.9.6/Python-3.9.6.tgz
安放位置,解压安装与编译
tar -zxvf Python-3.9.6.tgz # 解压
mkdir /usr/local/python39 # 创建链接位置目录
cd Python-3.9.6 # 切换目录
./configure --prefix=/usr/local/python39 # 配置文件到相应位置
make && make install # 编译与安装
配置软链接( 可以通过相应命令直接调用python)
rm -rf /usr/bin/python3 # 删除之前存在的链接指向,若不存在不报错
ln -s /usr/local/python39/bin/python3.9 /usr/bin/python3 # 链接python3
[root@VM-16-13-centos]# ln -s /usr/local/python37/bin/pip3.7 /usr/bin/pip3 # 链接 pip3
ln: failed to create symbolic link '/usr/bin/pip3': File exists
[root@VM-16-13-centos]# rm -rf /usr/bin/pip3
[root@VM-16-13-centos]# ln -s /usr/local/python37/bin/pip3.7 /usr/bin/pip3
检查
[root@VM-16-13-centos ~]# python3
Python 3.9.6 (default, Oct 16 2022, 11:31:29)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
学习扩展:创建虚拟环境
[root@VM-16-13-centos ~]# python3 -m venv tutorial-env
# 若有回显错误,执行,否则忽略
[root@VM-16-13-centos ~]# apt install python3.10-venv
# 激活
[root@VM-16-13-centos ~]# source tutorial-env/bin/activate
# 退出
[root@VM-16-13-centos ~]# deactivate
#删除虚拟环境
[root@VM-16-13-centos ~]# rmvirtualenv venv