[CentOS]更新Python 3.XX

Python(蟒蛇)是一個高階程式語言,他實現了modules(模組)、exceptions(例外)、dynamic typing(動態資料)、高階的資料形態以及classes(物件)。Python結合了卓越的力量與清晰的語法,有著與系統呼叫(system calls)溝通的界面。

Python的extensions(延伸功能)很強大,可以支援許多作業系統上面程式的界面。例如Unix-like、Mac、PC使用MS-DOS, Windows, Windows NT, OS/2等。標準的extensions例如PIL, COM, Numeric, oracledb, kjbuckets, tkinter, win32api等等的extensions,Python就像是個黏膠一般,可以很方便地將兩種異種軟體綁在一起工作。

同時Python也是2007年TIOBE所選出的年度程式語言,Google也有使用作為內部開發使用的程式語言。不過呢! CentOS上的Python兩百萬年沒更新過,始終是2.75的版本,這邊簡單做個更新Python的紀錄 ?

### CentOS8

dnf install -y python3 python3-devel python3-libs python3-setuptools python3-pip
alternatives --set python /usr/bin/python3
sudo pip3 install -U pip
sudo pip3 install -U setuptools
python -V
pip3 -V
easy_install --version

### CentOS7

# 透過EPEL的yum安裝

sudo yum remove -y epel-release remi
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y openssl-devel zlib-devel
yum install -y python3 python3-devel python3-libs python3-setuptools python3-pip python-urllib3

# 更新pip、setuptools

sudo pip3 install -U setuptools
sudo pip3 install -U pip
sudo python3.6 -m ensurepip

# 建立軟連結設定python3變成預設,並讓系統認識新的Python

unlink /usr/bin/python
unlink /usr/bin/python3
ln -s /usr/bin/python3.6 /usr/bin/python
ln -s /usr/bin/python3.6 /usr/bin/python3
unlink /usr/bin/pip3
ln -s /usr/local/bin/pip3.6 /usr/bin/pip3
/sbin/ldconfig

### 修改原先常用程式的python呼叫路徑

sed -i "s#python#python2#g" /usr/bin/yum
cat /usr/bin/yum | grep python
sed -i "s#python -tt#python2 -tt#g" /usr/bin/yum-builddep
cat /usr/bin/yum-builddep | grep python
sed -i "s#python -tt#python2 -tt#g" /usr/bin/yum-config-manager
cat /usr/bin/yum-config-manager | grep python
sed -i "s#python -tt#python2 -tt#g" /usr/bin/yum-debug-dump
cat /usr/bin/yum-debug-dump | grep python
sed -i "s#python -tt#python2 -tt#g" /usr/bin/yum-debug-restore
cat /usr/bin/yum-debug-restore | grep python
sed -i "s#python#python2#g" /usr/bin/yumdownloader
cat /usr/bin/yumdownloader | grep python
sed -i "s#python -tt#python2 -tt#g" /usr/bin/yum-builddep
cat /usr/bin/yum-builddep | grep python
sed -i "s#python -tt#python2 -tt#g" /usr/bin/yum-groups-manager
cat /usr/bin/yum-groups-manager | grep python
sed -i "s#python#python2#g" /usr/libexec/urlgrabber-ext-down
cat /usr/libexec/urlgrabber-ext-down | grep python
sed -i "s#python -tt#python2 -tt#g" /usr/sbin/yum-complete-transaction
cat /usr/sbin/yum-complete-transaction | grep python

# 檢查版本資訊

python -V
pip3 -V
easy_install --version

就這樣 0.0 大功告成~

About 窮苦人家的小孩

In every democracy, the people get the government they deserve. ~Alexis de Tocqueville
上一篇:
下一篇:

Check Also

designer.microsoft.com_Hawaii, USA - 002

Debian 11(bullseye)升級到Debian 12(bookworm)

Debian 12(bookw …

發佈留言