ubuntu18.04版本,python版本python2.7,python3.5,python3.6
因為安裝一些庫會安裝到python3.6上,而默認使用的是python2.7,使用python3,默認會使用python3.5,無法調用安裝包。
解決方法:
一、使用python xx.py運行程序時,加上版本號。比如python3.6 xx.py
二、1.要以root身份操作
1
|
yz@yz - pc:~$ sudo su |
2.確認本機下的python默認版本。調出終端,輸入python即可查看默認的版本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
root@yz - pc: / home / yz # python python 3.6 . 5 (default, apr 1 2018 , 05 : 46 : 30 ) [gcc 7.3 . 0 ] on linux type "help" , "copyright" , "credits" or "license" for more information. >>> exit() root@yz - pc: / home / yz # python2.7 python 2.7 . 15rc1 (default, apr 15 2018 , 21 : 51 : 34 ) [gcc 7.3 . 0 ] on linux2 type "help" , "copyright" , "credits" or "license" for more information. >>> exit() root@yz - pc: / home / yz # python3 python 3.6 . 5 (default, apr 1 2018 , 05 : 46 : 30 ) [gcc 7.3 . 0 ] on linux type "help" , "copyright" , "credits" or "license" for more information. >>> exit() root@yz - pc: / home / yz # python3.5 |
3.如何切換這兩個版本以及切換默認的python版本:
我們可以使用 update-alternatives 來為整個系統更改python 版本。以 root 身份登錄,首先羅列出所有可用的python 替代版本信息:
1
2
|
#update-alternatives --list python update - alternatives: error: no alternatives for python |
如果出現以上所示的錯誤信息,則表示 python 的替代版本尚未被update-alternatives 命令識別。想解決這個問題,我們需要更新一下替代列表,將python2.7 和 python3.6放入其中。
1
2
3
4
|
? # 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 # update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2 update - alternatives: using / usr / bin / python3. 4 to provide / usr / bin / python (python) in auto mode |
--install 選項使用了多個參數用于創建符號鏈接。最后一個參數指定了此選項的優先級,如果我們沒有手動來設置替代選項,那么具有最高優先 級的選項就會被選中。這個例子中,我們為/usr/bin/python3.4 設置的優先級為2,所以update-alternatives 命 令會自動將它設置為默認 python 版本。
1
2
|
# python --version python 3.5 . 2 |
接下來,我們再次列出可用的 python 替代版本。
1
2
3
|
# update-alternatives --list python / usr / bin / python2. 7 / usr / bin / python3. 5 |
現在開始,我們就可以使用下方的命令隨時在列出的 python 替代版本中任意切換了。
(這一步是最關鍵的)
1
|
# update-alternatives --config python |
下面就簡單了,會提示你輸入序號,你想用哪個版本為默認,就輸入序號就可以了!
結束!
參考文章:http://www.ythuaji.com.cn/article/175961.html
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/qq_34343669/article/details/82888992