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]: