濮阳杆衣贸易有限公司

主頁 > 知識庫 > Ubuntu16.04 安裝多個python版本的問題及解決方法

Ubuntu16.04 安裝多個python版本的問題及解決方法

熱門標簽:B52系統(tǒng)電梯外呼顯示E7 怎么辦理400客服電話 銀川電話機器人電話 高德地圖標注收入咋樣 沈陽防封電銷電話卡 萊蕪電信外呼系統(tǒng) 企業(yè)微信地圖標注 地圖標注多個 鶴壁手機自動外呼系統(tǒng)違法嗎

Ubuntu16.04自帶python2.7與python3.5,某個項目編譯卻要求python版本大于等于3.7,遂考慮在原系統(tǒng)基礎(chǔ)上再安裝python3.8。

1 下載安裝python3.8

Ubuntu 官方 apt 庫中還未收錄 python 3.8,因此添加 deadsnakes PPA 源安裝python3.8,否則會出現(xiàn)以下錯誤

錯誤1

E: 無法定位軟件包 python3.8
E: 無法按照 glob ‘python3.8' 找到任何軟件包
E: 無法按照正則表達式 python3.8 找到任何軟件包

解決方法:運行以下指令安裝python3.8

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.8

此時python3版本還是指向python3.5,可以輸入

cd /usr/bin  ll

查看

2 修改python3默認指向

sudo rm python3
sudo ln -s python3.8 python3

查看python版本驗證修改成功:

$ python3 --version
python3.8.9

3 無法打開終端解決方案

按1、2步驟安裝完python3后,一般無法打開終端
錯誤2

$ gnome-terminal
Traceback (most recent call last):
  File "/usr/bin/gnome-terminal", line 9, in module>
    from gi.repository import GLib, Gio
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in module>
    from . import _gi
ImportError: cannot import name '_gi'

解決方法:

cd /usr/lib/python3/dist-packages/gi/
# 下面的35 改成38 表示從py3.5改到py3.8
sudo mv _gi_cairo.cpython-35m-x86_64-linux-gnu.so  _gi_cairo.cpython-38m-x86_64-linux-gnu.so
sudo mv _gi.cpython-35m-x86_64-linux-gnu.so _gi.cpython-38m-x86_64-linux-gnu.so

接下來修改

sudo gedit /usr/bin/gnome-terminal

將python3改為python

問題解決。

4 python版本的卸載

sudo apt remove python3.8
sudo apt autoremove python3.8

5 python多版本管理

參考https://www.jb51.net/article/221437.htm,值得注意,僅按該博文的方式配置仍會打不開終端,建議先按照本文方式配置后再添加管理。

將 python 各版本添加到 update-alternatives

$ which python3.8
/usr/bin/python3.8

$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

$ which python3.5
/usr/bin/python3.5

$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 2

通過下面配置切換版本

$ sudo update-alternatives --config python3


There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.5   2         auto mode
  1            /usr/bin/python3.5   2         manual mode
  2            /usr/bin/python3.8   1         manual mode

Press enter> to keep the current choice[*], or type selection number: 2

6 升級pip3/pip

對于初次安裝python的Ubuntu系統(tǒng)而言,pip等級較低,這種情況下進行pip install高版本庫可能會出現(xiàn)一系列的問題,例如:

錯誤3:AttributeError: module ‘platform' has no attribute ‘linux_distribution'
解決方法:對pip版本進行升級

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py --force-reinstall

到此這篇關(guān)于Ubuntu16.04 安裝多個python版本的文章就介紹到這了,更多相關(guān)Ubuntu16.04 安裝python內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • vitrualBox+ubuntu16.04安裝python3.6最新教程及詳細步驟
  • Ubuntu16.04安裝python3.6.5步驟詳解
  • 詳解Ubuntu16.04安裝Python3.7及其pip3并切換為默認版本
  • 在ubuntu16.04中將python3設(shè)置為默認的命令寫法
  • ubuntu16.04在python3 下創(chuàng)建Django項目并運行的操作方法
  • ubuntu16.04制作vim和python3的開發(fā)環(huán)境
  • Ubuntu16.04/樹莓派Python3+opencv配置教程(分享)
  • Linux-ubuntu16.04 Python3.5配置OpenCV3.2的方法

標簽:安慶 呼倫貝爾 烏魯木齊 呼倫貝爾 三亞 銀川 湘西 葫蘆島

巨人網(wǎng)絡(luò)通訊聲明:本文標題《Ubuntu16.04 安裝多個python版本的問題及解決方法》,本文關(guān)鍵詞  Ubuntu16.04,安裝,多個,python,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Ubuntu16.04 安裝多個python版本的問題及解決方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于Ubuntu16.04 安裝多個python版本的問題及解決方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    寻乌县| 安福县| 马边| 珲春市| 桓台县| 咸阳市| 应城市| 突泉县| 台中县| 任丘市| 岢岚县| 乌什县| 松阳县| 绥德县| 汤阴县| 轮台县| 神农架林区| 西乌珠穆沁旗| 河西区| 长泰县| 桂东县| 大港区| 乡宁县| 阳高县| 东海县| 琼结县| 济宁市| 常山县| 基隆市| 尉犁县| 蓬安县| 尼木县| 潮州市| 龙泉市| 三门县| 乌鲁木齐县| 大关县| 屏东县| 仪征市| 德庆县| 白水县|