Ubuntu操作系統(tǒng)自帶Python,18.04的版本分別為Python2.7.17和Python3.6.9。
root@linux:/# python --version
Python 2.7.17
root@linux:/# python3 --version
Python 3.6.9
root@linux:/# ll /usr/bin/ | grep python*
-rwxr-xr-x 1 root root 1056 Apr 16 2018 dh_python2*
lrwxrwxrwx 1 root root 23 Sep 30 2020 pdb2.7 -> ../lib/python2.7/pdb.py*
lrwxrwxrwx 1 root root 23 Oct 8 2020 pdb3.6 -> ../lib/python3.6/pdb.py*
lrwxrwxrwx 1 root root 31 Oct 25 2018 py3versions -> ../share/python3/py3versions.py*
lrwxrwxrwx 1 root root 9 Apr 16 2018 python -> python2.7*
lrwxrwxrwx 1 root root 9 Apr 16 2018 python2 -> python2.7*
-rwxr-xr-x 1 root root 3628976 Sep 30 2020 python2.7*
lrwxrwxrwx 1 root root 9 Oct 25 2018 python3 -> python3.6*
-rwxr-xr-x 2 root root 4526456 Oct 8 2020 python3.6*
-rwxr-xr-x 2 root root 4526456 Oct 8 2020 python3.6m*
-rwxr-xr-x 1 root root 1018 Oct 29 2017 python3-jsondiff*
-rwxr-xr-x 1 root root 3661 Oct 29 2017 python3-jsonpatch*
-rwxr-xr-x 1 root root 1342 May 2 2016 python3-jsonpointer*
-rwxr-xr-x 1 root root 398 Nov 16 2017 python3-jsonschema*
lrwxrwxrwx 1 root root 10 Oct 25 2018 python3m -> python3.6m*
lrwxrwxrwx 1 root root 29 Apr 16 2018 pyversions -> ../share/python/pyversions.py*
root@linux:/#
如何設(shè)置Python的默認版本?
可以通過修改軟鏈接的方式進行:
root@linux:/# rm /usr/bin/python
root@linux:/# ln -s /usr/bin/python3.6 /usr/bin/python
root@linux:/# python --version
Python 3.6.9
還可以通過update-alternatives進行設(shè)置,update-alternatives進行軟件版本的切換:
root@linux:/# update-alternatives --list python
update-alternatives: error: no alternatives for python
root@linux:/# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
root@linux:/# update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python (python) in auto mode
root@linux:/# update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.6
root@linux:/# update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.6 2 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.6 2 manual mode
Press to keep the current choice[*], or type selection number: 2
root@linux:/# python --version
Python 3.6.9
alternatives的管理目錄 /etc/alternatives,指向可執(zhí)行的文件:
root@linux:/# cd /etc/alternatives/
root@linux:/etc/alternatives# ll
......
lrwxrwxrwx 1 root root 18 Feb 7 16:51 python -> /usr/bin/python3.6*
......
如何安裝Python新版本?
可以從源碼進行安裝
(1)環(huán)境準備
apt update
apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Python的解釋器是用C語言編寫的,從源碼開始安裝需要C語言的編譯環(huán)境,Ubuntu提供了build-essential軟件包,該軟件包依賴gcc\\g++,因此安裝build-essential,這些依賴包一起安裝了。
root@linux:~# apt-cache depends build-essential
build-essential
|Depends: libc6-dev
Depends:
libc6-dev
Depends: gcc
Depends: g++
Depends: make
make-guile
Depends: dpkg-dev
(2)下載源代碼
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
root@linux:~# wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
--2022-02-07 21:29:38-- https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
Resolving www.python.org (www.python.org)... 151.101.72.223, 2a04:4e42:1a::223
Connecting to www.python.org (www.python.org)|151.101.72.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23949883 (23M) [application/octet-stream]
Saving to: aPython-3.8.0.tgza
Python-3.8.0.tgz 100%[===========================================================================>] 22.84M 16.8KB/s in 29m 4s
2022-02-07 21:58:42 (13.4 KB/s) - aPython-3.8.0.tgza saved [23949883/23949883]
(3)安裝Python
tar -xf Python-3.8.0.tgz
cd Python-3.8.0
root@linux:~# cd Python-3.8.0
root@linux:~/Python-3.8.0# ll
total 1084
drwxr-xr-x 17 1000 1000 4096 Oct 14 2019 ./
drwx------ 19 root root 4096 Feb 7 22:06 ../
-rw-r--r-- 1 1000 1000 11000 Oct 14 2019 aclocal.m4
-rw-r--r-- 1 1000 1000 630 Oct 14 2019 CODE_OF_CONDUCT.md
-rwxr-xr-x 1 1000 1000 44166 Oct 14 2019 config.guess*
-rwxr-xr-x 1 1000 1000 36251 Oct 14 2019 config.sub*
-rwxr-xr-x 1 1000 1000 503509 Oct 14 2019 configure*
-rw-r--r-- 1 1000 1000 166233 Oct 14 2019 configure.ac
drwxr-xr-x 18 1000 1000 4096 Oct 14 2019 Doc/
drwxr-xr-x 2 1000 1000 4096 Oct 14 2019 Grammar/
drwxr-xr-x 4 1000 1000 4096 Oct 14 2019 Include/
-rwxr-xr-x 1 1000 1000 15368 Oct 14 2019 install-sh*
drwxr-xr-x 33 1000 1000 4096 Oct 14 2019 Lib/
-rw-r--r-- 1 1000 1000 12769 Oct 14 2019 LICENSE
drwxr-xr-x 2 1000 1000 4096 Oct 14 2019 m4/
drwxr-xr-x 8 1000 1000 4096 Oct 14 2019 Mac/
-rw-r--r-- 1 1000 1000 67201 Oct 14 2019 Makefile.pre.in
drwxr-xr-x 2 1000 1000 4096 Oct 14 2019 Misc/
drwxr-xr-x 14 1000 1000 4096 Oct 14 2019 Modules/
drwxr-xr-x 4 1000 1000 4096 Oct 14 2019 Objects/
drwxr-xr-x 3 1000 1000 4096 Oct 14 2019 Parser/
drwxr-xr-x 6 1000 1000 4096 Oct 14 2019 PC/
drwxr-xr-x 2 1000 1000 4096 Oct 14 2019 PCbuild/
drwxr-xr-x 2 1000 1000 4096 Oct 14 2019 Programs/
-rw-r--r-- 1 1000 1000 45194 Oct 14 2019 pyconfig.h.in
drwxr-xr-x 3 1000 1000 4096 Oct 14 2019 Python/
-rw-r--r-- 1 1000 1000 9978 Oct 14 2019 README.rst
-rw-r--r-- 1 1000 1000 104153 Oct 14 2019 setup.py
drwxr-xr-x 23 1000 1000 4096 Oct 14 2019 Tools/
./configure --enable-optimizations
......
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup.local
creating Makefile
root@linux:~/Python-3.8.0# ls
aclocal.m4 config.log configure Grammar Lib Mac Makefile.pre.in Objects PCbuild pyconfig.h.in setup.py
CODE_OF_CONDUCT.md config.status configure.ac Include LICENSE Makefile Misc Parser Programs Python Tools
config.guess config.sub Doc install-sh m4 Makefile.pre Modules PC pyconfig.h README.rst
root@linux:~/Python-3.8.0#
make -j 8
........
unning build_scripts
copying and adjusting /root/Python-3.8.0/Tools/scripts/pydoc3 -> build/scripts-3.8
copying and adjusting /root/Python-3.8.0/Tools/scripts/idle3 -> build/scripts-3.8
copying and adjusting /root/Python-3.8.0/Tools/scripts/2to3 -> build/scripts-3.8
changing mode of build/scripts-3.8/pydoc3 from 644 to 755
changing mode of build/scripts-3.8/idle3 from 644 to 755
changing mode of build/scripts-3.8/2to3 from 644 to 755
renaming build/scripts-3.8/pydoc3 to build/scripts-3.8/pydoc3.8
renaming build/scripts-3.8/idle3 to build/scripts-3.8/idle3.8
renaming build/scripts-3.8/2to3 to build/scripts-3.8/2to3-3.8
make[1]: Leaving directory '/root/Python-3.8.0'
root@linux:~/Python-3.8.0#
make altinstall
.......
Looking in links: /tmp/tmp84bibaoh
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.2.3 setuptools-41.2.0
root@linux:/usr/local/bin# ll
total 16936
drwxr-xr-x 2 root root 4096 Feb 7 22:19 ./
drwxr-xr-x 10 root root 4096 Apr 24 2019 ../
-rwxr-xr-x 1 root root 101 Feb 7 22:19 2to3-3.8*
-rwxr-xr-x 1 root root 241 Feb 7 22:19 easy_install-3.8*
-rwxr-xr-x 1 root root 99 Feb 7 22:19 idle3.8*
-rwxr-xr-x 1 root root 223 Feb 7 22:19 pip3.8*
-rwxr-xr-x 1 root root 84 Feb 7 22:19 pydoc3.8*
-rwxr-xr-x 1 root root 17307376 Feb 7 22:19 python3.8*
-rwxr-xr-x 1 root root 3087 Feb 7 22:19 python3.8-config*
如何卸載Python?
apt-get remove python3.8
apt-get remove --auto-remove python3.8
apt-get purge python3.8
apt-get purge --auto-remove python3.8
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。
舉報投訴
-
操作系統(tǒng)
+關(guān)注
關(guān)注
37文章
7266瀏覽量
128071 -
Ubuntu
+關(guān)注
關(guān)注
5文章
601瀏覽量
32579 -
python
+關(guān)注
關(guān)注
56文章
4849瀏覽量
89126
發(fā)布評論請先 登錄
相關(guān)推薦
熱點推薦
python計算庫環(huán)境配置(二)及燒寫模式介紹
本文介紹云芯一號(rk3399) 微型服務(wù)器的python環(huán)境配置一些記錄。本Arm服務(wù)器算力不是很高主要面向服務(wù)類應(yīng)用,但是可以跑一些簡單的模...
python環(huán)境變量的配置pip
Python環(huán)境變量的配置和使用是每個Python開發(fā)者都需要了解和掌握的基本技能之一。在本文中,我們將詳細介紹如何正確配置
termux如何搭建python游戲
模擬器,支持通過APT包管理器安裝軟件。搭建Python游戲開發(fā)環(huán)境前需完成以下基礎(chǔ)配置:
1. 更換國內(nèi)源
為提升下載速度,需替換Termux默認源為清華源,執(zhí)行以下命令:
```bash
發(fā)表于 08-29 07:06

2021最新Python爬蟲+數(shù)據(jù)可視化-3.python環(huán)境配置以及編輯器的安裝 #硬聲創(chuàng)作季
編程語言python
Hello,World!
發(fā)布于 :2022年08月29日 20:19:21
【HarmonyOS HiSpark AI Camera】開箱以及環(huán)境配置分享
/third_party/ffmpeg/ffmpeg-y清空ffmpeg-y里面的所有文件,然后把從gitee上下的替換進去就行綜上,如果確定自己的python環(huán)境配置沒問題的話,遇到編譯錯誤可以嘗試去gitee
發(fā)表于 11-25 17:54
如何對RK3399Pro python環(huán)境進行配置呢
RK3399Pro python環(huán)境有哪些配置呢?如何對RK3399Pro python環(huán)境進行配置
發(fā)表于 02-11 07:20
python基礎(chǔ)教程之如何使用python進行環(huán)境搭建
Python 有 Python 2 和 Python 3 兩個版本。 語法有些區(qū)別。 保險起見, 我安裝Python配置pydev解釋器安裝
發(fā)表于 10-25 16:55
?34次下載
python如何配置虛擬環(huán)境?
python 的虛擬環(huán)境可以為一個 python 項目提供獨立的解釋環(huán)境、依賴包等資源,既能夠很好的隔離不同項目使用不同 python 版本
發(fā)表于 01-07 17:12
?1171次閱讀
配置Python開發(fā)環(huán)境的DeepStream容器
范例,并不適用于 DeepStream 的 Python 環(huán)境,因為還需要安裝 Gstreamer 的 Gst-Python 與 DeepStream 的 PyBinding 與兩個元件。
如何搭建Python編程環(huán)境
Python是一種高級編程語言,被廣泛用于科學計算、數(shù)據(jù)分析、人工智能、Web開發(fā)等領(lǐng)域。想要學習Python編程,首先需要搭建一個合適的編程環(huán)境。本文將為您介紹如何搭建Python編
如何測試Python環(huán)境
在編程中,測試是一項重要的工作,可以幫助我們驗證代碼的正確性和穩(wěn)定性。在Python編程環(huán)境中,同樣需要進行測試來確保Python的安裝和配置是正確的。在本篇文章中,我們將介紹如何測試
如何配置Python環(huán)境變量
配置Python環(huán)境變量是在安裝Python解釋器后的一項重要步驟,它允許您在任何位置都可以通過命令行或腳本運行Python解釋器,使
pycharm怎么配置python環(huán)境變量
PyCharm 是一種以 Python 為主的集成開發(fā)環(huán)境 (IDE),它提供了一系列的功能用于開發(fā)、調(diào)試、測試和部署 Python 程序。在使用 PyCharm 開發(fā) Python
python軟件對電腦配置要求
Python是一種流行的編程語言,它在許多不同的領(lǐng)域中被廣泛使用,例如網(wǎng)站開發(fā)、數(shù)據(jù)科學和機器學習等。對于使用Python的開發(fā)者來說,了解Python軟件的電腦配置要求是非常重要的。
python運行環(huán)境的安裝和配置
Python是一種非常流行的編程語言,廣泛應(yīng)用于科學計算、Web開發(fā)、人工智能等領(lǐng)域。為了能夠正常運行Python程序,我們需要先安裝和配置Python運行
評論