centos7 下 yum安装与卸载python3

yum 源准备

1、更新一下yum:

sudo yum -y update

该 -y 标志用于提醒系统我们知道我们正在进行更改,免去终端提示我们要确认再继续。普通用户需要sudo进行提权。

2、安装yum-utils 【一组扩展和补充yum的实用程序和插件】

sudo yum -y install yum-utils

3、安装CentOS开发工具 【用于允许您从源代码构建和编译软件】

sudo yum -y groupinstall development

安装Python3

1、安装EPEL:

sudo yum -y install epel-release

2、安装IUS软件源:

sudo yum -y install https://mirrors.aliyun.com/ius/ius-release-el7.rpm

3、安装Python3.6:

sudo yum -y install python36

4、安装pip3:
由于上面已经给你全装好了,无需再安装了,这一步可以略过。

sudo yum -y install python36-pip

5、检查一下安装情况,分别执行命令查看:

python3.6 -V
pip3.6 -V

在 /usr/lib/目录下可以看到Python3.6的文件夹

添加软链接(拓展)

使用python3去使用Python3.6:

ln -s /usr/bin/python3.6 /usr/bin/python3

复制代码pip3.6同理:

ln -s /usr/bin/pip3.6 /usr/bin/pip3

我们可以看到,软链接是创建成功了的,无需我们再创建。

  • 软链接可以跨文件系统,硬链接不可以;
  • 软链接可以对目录进行连接,硬链接不可以;
  • 删除源文件之后,软链接失效,硬链接无影响;
  • 两种链接都可以通过命令 ln 来创建;
  • ln 默认创建的是硬链接;
  • 使用 -s 参数可以创建软链接。


输入exit()退出Python ide

配置使用国内源安装第三方模块

创建配置文件

配置 pip3 使用国内源

mkdir ~/.pip
vi ~/.pip/pip.conf
# Windows 下使用 pip.ini
(1):在windows文件管理器中,输入 %APPDATA%
(2):会定位到一个新的目录下,在该目录下新建pip文件夹,然后到pip文件夹里面去新建个pip.ini文件

写入如下内容:

[global]
timeout = 6000
index-url=https://mirrors.aliyun.com/pypi/simple

豆瓣源: https://pypi.douban.com/simple/

阿里源: https://mirrors.aliyun.com/pypi/simple

清华: https://pypi.tuna.tsinghua.edu.cn/simple

阿里云: http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学: http://pypi.hustunique.com/

山东理工大学: http://pypi.sdutlinux.org/

示例:
比如安装一个执行远程主机命令的模块

[root@newrain ~]# pip3 install gnureadline
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting gnureadline
  Downloading https://mirrors.aliyun.com/pypi/packages/2b/36/60b53a1793af9a60539b5ee6fed4f3702280bd5a88ab41600a51510002a1/gnureadline-8.0.0-cp37-cp37m-manylinux1_x86_64.whl (283kB)
    100% |████████████████████████████████| 286kB 387kB/s 
Installing collected packages: gnureadline
Successfully installed gnureadline-8.0.0
You are using pip version 19.0.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command. # 最后两行为警告内容,无需理会

卸载python3

注意卸载的时候python后跟的2或3或者什么都不跟,否则会全部删除

      rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps       卸载pyhton3
      whereis python3 |xargs rm -frv           删除所有残余文件
      成功卸载!
      whereis   python       查看现有安装的python

Ipython 交互式解释器

Ipython 简介

IPython外加一个文本编辑器

Windows系统下是IPython加notepad++,Linux系统下是IPython加vim配合使用,写起代码来体验很流畅,很容易获取到写代码时候的那种“流体验”。

IPython的设计目的是在交互式计算和软件开发这两个方面最大化地提高生产力,它鼓励一种“执行-探索”的工作模式,支持matplotlib等库的绘图操作。同时IPython还提供一个基于WEB的交互式浏览器开发环境(Jupyter Notebook),用起来也很不错。

安装 Ipython

安装 python-devel

​ python-dev或python-devel称为是python的开发包,其中包括了一些用C/Java/C#等编写的python扩展在编译的时候依赖的头文件等信息。

比如:我们在编译一个用C语言编写的python扩展模块时,因为里面会有#include<Python.h>等这样的语句,因此我们就需要先安装python-devel开发包

执行以下命令安装即可(需要有 epel 源支持):

yum -y install python-devel

安装 ipython

pip3 install ipython

启动 ipython

[root@localhost ~]# ipython
Python 3.6.5 (default, Mar  6 2019, 06:36:12) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:  

退出 ipython

[root@localhost ~]# ipython
Python 3.6.5 (default, Mar  6 2019, 06:36:12) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: exit                                                                                                                                                      
[root@localhost ~]# 

使用 ipython

[root@localhost ~]# ipython
Python 3.6.5 (default, Mar  6 2019, 06:36:12) 
Type 'copyright', 'credits' or 'license' for more informat
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' 
#定义一个字符串
In [1]: str = "hello"                                     
#tab显示字符串类型的方法
In [2]: str. 
           capitalize()   encode()       format()        
           casefold()     endswith()     format_map()    
           center()       expandtabs()   index()    
           count()        find()         isalnum()      

[root@localhost ~]# ipython
Python 3.6.5 (default, Mar  6 2019, 06:36:12) 
Type 'copyright', 'credits' or 'license' for more informat
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' 

In [1]: str = "hello"                                     
# 定义一个数字型
In [2]: int = 1                                          
# tab显示数字类型的方法
In [3]: int. 
             bit_length() from_bytes() real        
             conjugate()  imag         to_bytes()  
             denominator  numerator                   
# 执行系统命令,加!是以变量的形式执行命令                                                    In [4]: !pwd                                             
/root

In [5]: pwd                                              
Out[5]: '/root'

In [6]: cd /home/                                        
/home

In [7]: pwd                                              
Out[7]: '/home'

In [8]: ls                                               

In [9]: ls /                                             
bin@   etc/   lib64@  opt/   run/   sys/  var/
boot/  home/  media/  proc/  sbin@  tmp/
dev/   lib@   mnt/    root/  srv/   usr/

In [10]:   
posted @ 2020-07-11 11:40  Sureing  阅读(7820)  评论(0编辑  收藏  举报