Linux – 安裝 Python & pip

測試環境為 CentOS 8 x86_64 (虛擬機)

安裝 Python (與 pip , Python 套件管理程式)

[root@localhost ~]# yum install python
Last metadata expiration check: 0:11:09 ago on Tue May 10 23:09:33 2022.
No match for argument: python
There are following alternatives for "python": python2, python36, python38, python39
Error: Unable to find a match: python

需指定安裝的 Python 版本.

[root@localhost ~]# yum -y install python39
Last metadata expiration check: 0:11:20 ago on Tue May 10 23:09:33 2022.
Dependencies resolved.
 Package                         Architecture Version                                      Repository       Size
 python39                        x86_64       3.9.7-1.module_el8.6.0+930+10acc06f          appstream        33 k
Installing dependencies:
 python39-libs                   x86_64       3.9.7-1.module_el8.6.0+930+10acc06f          appstream       8.2 M
 python39-pip-wheel              noarch       20.2.4-6.module_el8.6.0+930+10acc06f         appstream       1.3 M
 python39-setuptools-wheel       noarch       50.3.2-4.module_el8.6.0+930+10acc06f         appstream       497 k
Installing weak dependencies:
 python39-pip                    noarch       20.2.4-6.module_el8.6.0+930+10acc06f         appstream       2.0 M
 python39-setuptools             noarch       50.3.2-4.module_el8.6.0+930+10acc06f         appstream       871 k
Enabling module streams:
 python39                                     3.9                                                               

Transaction Summary
Install  6 Packages

檢視一下 python 版本.

[root@localhost ~]# python3 --version
Python 3.6.8

檢視一下 pip (Python 套件管理程式) 的版本.

[root@localhost ~]# pip -V
pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

更新 pip 到最新版本.

[root@localhost ~]# python3 -m pip install --upgrade pip

檢視 pip 預設安裝了哪些套件.

[root@localhost ~]# pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
asn1crypto (0.24.0)
blivet (3.4.0)
Brlapi (0.6.7)
cffi (1.11.5)
chardet (3.0.4)
SSSDConfig (2.6.2)
subscription-manager (1.28.28)
syspurpose (1.28.28)
systemd-python (234)
urllib3 (1.24.2)
webencodings (0.5.1)

如果更新 pip 所有套件需要使用到 pip-view 套件.

[root@localhost ~]# pip install pip-review

互動式更新 (會一個一個套件詢問).

[root@localhost ~]# pip-review --local --interactive


[root@localhost ~]# pip-review --local --auto

測試一下簡單的 python 程式,只有透過 print 函數列印出 Hello .

[root@localhost ~]# vim
print ('Hello')

執行 Python 程式.

[root@localhost ~]# python3 



這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料