CentOS 7 安装Python3的配置
程序员文章站
2022-05-29 12:14:39
...
接着:
Python3.7源码包编译安装 https://blog.csdn.net/jiduochou963/article/details/86694775
一、python部分
切换(修改默认链接):
$ cd /usr/bin/
$ mv python python.back
$ mv python-config python-config.back
确认一下:
[[email protected] bin]# ll | grep python
lrwxrwxrwx. 1 root root 9 3月 22 09:52 python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 10月 31 07:46 python2.7
-rwxr-xr-x. 1 root root 1835 10月 31 07:46 python2.7-config
lrwxrwxrwx. 1 root root 16 3月 24 12:37 python2-config -> python2.7-config
lrwxrwxrwx. 1 root root 7 3月 22 09:52 python.back -> python2
lrwxrwxrwx. 1 root root 14 3月 24 12:37 python-config.back -> python2-config
[[email protected] bin]#
然后设置硬链接:
$ cd /usr/local/python3/bin
$ ln python3.7 /usr/bin/python3.7
$ ln python3.7m-config /usr/bin/python3.7m-config
确认一下:
[[email protected] bin]# cd /usr/bin/
[[email protected] bin]# ll | grep python
lrwxrwxrwx. 1 root root 9 3月 22 09:52 python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 10月 31 07:46 python2.7
-rwxr-xr-x. 1 root root 1835 10月 31 07:46 python2.7-config
lrwxrwxrwx. 1 root root 16 3月 24 12:37 python2-config -> python2.7-config
-rwxr-xr-x. 3 root root 13979392 3月 24 11:32 python3.7
-rwxr-xr-x. 2 root root 3105 3月 24 11:33 python3.7m-config
lrwxrwxrwx. 1 root root 7 3月 22 09:52 python.back -> python2
lrwxrwxrwx. 1 root root 14 3月 24 12:37 python-config.back -> python2-config
设置软链接:
$ ln -s python3.7 python
$ ln -s python3.7 python3
$ ln -s python3.7m-config python-config
$ ln -s python3.7m-config python3-config
确认一下:
[[email protected] bin]# ll | grep python
lrwxrwxrwx. 1 root root 9 3月 24 20:54 python -> python3.7
lrwxrwxrwx. 1 root root 9 3月 22 09:52 python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 10月 31 07:46 python2.7
-rwxr-xr-x. 1 root root 1835 10月 31 07:46 python2.7-config
lrwxrwxrwx. 1 root root 16 3月 24 12:37 python2-config -> python2.7-config
lrwxrwxrwx. 1 root root 9 3月 24 20:54 python3 -> python3.7
-rwxr-xr-x. 3 root root 13979392 3月 24 11:32 python3.7
-rwxr-xr-x. 2 root root 3105 3月 24 11:33 python3.7m-config
lrwxrwxrwx. 1 root root 17 3月 24 21:16 python3-config -> python3.7m-config
lrwxrwxrwx. 1 root root 7 3月 22 09:52 python.back -> python2
lrwxrwxrwx. 1 root root 17 3月 24 20:55 python-config -> python3.7m-config
lrwxrwxrwx. 1 root root 14 3月 24 12:37 python-config.back -> python2-config
[[email protected] bin]#
二、pip部分
设置硬链接:
[[email protected] bin]# pwd
/usr/local/python3/bin
[[email protected] bin]# ln pip3 /usr/bin/pip3
确认并设置软链接:
[[email protected] bin]# ll | grep pip
-rwxr-xr-x. 1 root root 2291 7月 31 2015 lesspipe.sh
[[email protected] bin]# pwd
/usr/bin
[[email protected] bin]# ll | grep pip
-rwxr-xr-x. 1 root root 2291 7月 31 2015 lesspipe.sh
-rwxr-xr-x. 2 root root 232 3月 24 11:35 pip3
[[email protected] bin]# ln -s pip3 pip
[[email protected] bin]# ll | grep pip
-rwxr-xr-x. 1 root root 2291 7月 31 2015 lesspipe.sh
lrwxrwxrwx. 1 root root 4 3月 24 21:29 pip -> pip3
-rwxr-xr-x. 2 root root 232 3月 24 11:35 pip3
[[email protected] bin]#
三、其他注意事项
切换到 python3 后,可能会造成一些命令不能使用,如:yum。
这是因为这些命令不兼容 python3,只需要将其修改为使用原先的python2即可。
把文件头部的#!/usr/bin/python
改成#!/usr/bin/python2.7
。
[[email protected] onefine]# yum
File "/usr/bin/yum", line 30
except KeyboardInterrupt, e:
^
SyntaxError: invalid syntax
[[email protected] onefine]# cd /usr/bin/
[[email protected] bin]# cat yum
#!/usr/bin/python
...省略
[[email protected] bin]# vim yum
#!/usr/bin/python2.7
...省略
[[email protected] bin]# cat yum
#!/usr/bin/python2.7
...省略
[[email protected] bin]#
[[email protected] bin]# yum
已加载插件:fastestmirror
您需要给出命令
Usage: yum [options] COMMAND
List of Commands:
check 检查 RPM 数据库问题
...省略
四、测试
[[email protected] ~]# python --version
Python 3.7.2
[[email protected] ~]# pip --version
pip 19.0.3 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[[email protected] ~]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
[[email protected] ~]#
参考:
Linux下切换Python版本 https://blog.csdn.net/hangdongzhang/article/details/78405483
防火墙不能启动请参阅:
Centos7 安装python3详细教程,解决升级后不兼容问题 https://blog.51cto.com/9406836/2140783
推荐阅读
-
Linux - CentOS 7 安装 .Net Core 运行环境
-
MySQL 5.6 (Win7 64位)下载、安装与配置图文教程
-
在CentOS上安装搭建PHP+Apache+Mysql的服务器环境
-
Mysql5.7.11在windows10上的安装与配置(解压版)
-
Jenkins的安装配置详解
-
CentOS6.5下RPM方式安装mysql5.6.33的详细教程
-
CentOS 7 中以命令行方式安装 MySQL 5.7.11 for Linux Generic 二进制版本教程详解
-
最全的mysql 5.7.13 安装配置方法图文教程(linux) 强烈推荐!
-
CentOS7.2虚拟机上安装MySQL 5.6.32的教程
-
IIS7伪静态web.config配置的方法和规则