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
[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
=================================================================================================================
Installing:
 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 預設安裝了哪些套件.

[root@localhost ~]# pip
pip-3                   pip-3.9                 pip3.6                  pipewire
pip-3.6                 pip3                    pip3.9                  pipewire-media-session
[root@localhost ~]# pip3 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)

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

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

執行 Python 程式.

[root@localhost ~]# python3 hello.py 
Hello
沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。

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