centos安装python3

官方下载安装包

https://www.python.org/ftp/python/3.7.12/Python-3.7.12.tgz

上传服务器

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  libffi-devel gcc make


./configure --prefix=/usr/local/python3
make
make install

配置环境变量

vim /etc/profile
export PYTHON_HOME=/usr/local/python3
export PATH=$PYTHON_HOME/bin:$PATH

[root@localhost ~]# source /etc/profile
[root@localhost ~]# pip3 -V
pip 20.1.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[root@localhost ~]# python3.7 -V
Python 3.7.12

生成py3的配置环境

[root@bogon learning_log]# python3 -m venv ll_env
[root@bogon learning_log]# ls
ll_env
[root@bogon learning_log]# ll ll_env/
总用量 4
drwxr-xr-x 2 root root 173 10月 17 15:10 bin
drwxr-xr-x 2 root root 6 10月 17 15:10 include
drwxr-xr-x 3 root root 23 10月 17 15:10 lib
lrwxrwxrwx 1 root root 3 10月 17 15:10 lib64 -> lib
-rw-r–r-- 1 root root 84 10月 17 15:10 pyvenv.cfg
[root@bogon learning_log]#

如果可行就执行 source ll_env/bin/activate
写入linux环境变量 cd /opt/learning_log && source ll_env/bin/activate

如果服务器多个python版本,可以在使用时调用下述脚本即可
cat /opt/py3_vent.sh
#!/bin/bash
source  /opt/py3/bin/activate


如果需要退出,在py3的环境中执行 `deactivate` 命令即可

centos安装python3_第1张图片

如果你想在命令行直接运行python3 参考

mv /usr/bin/python /usr/bin/python.bak && ln -s /usr/local/python-3.10/bin/python3.10 /usr/bin/python
centos安装python3_第2张图片

centos安装python3_第3张图片

你可能感兴趣的:(python,linux)