python3 與 python2 的多版本共存(Linux)

來源:互聯網
上載者:User

標籤:

python3已經出來有些許時候了,python3相比python2進行了大量的改進,包括文法,新的功能,還有最佳化。雖然很多庫已經同時支援 python2和python3了,但是有些庫仍然沒有很好的支援python3,因此有時我們還是需要使用python2。 博主是在去年開始學python的,作為沒有曆史包袱的初學者,當時自然而然的選則了python3來進行學習,但是在安裝了新的python3後,新安裝的python3不可避免的與系統內建的python2產生了一些衝突。包括不同版本的調用,不同版本的python庫安裝工具(pip,easy_install)。 本文就python2和pyhon3共存的環境進行了說明,包括python3的安裝,pip的安裝,以及如何調用這兩種python版本。 ubuntu的配置方法1、安裝python2多數linux發行版都內建了python2,不與要單獨安裝。
$ sudo apt-get install python2
2、安裝easy_install for python2

使用wget安裝(可能需要root許可權)[推薦]

$ wget https://bootstrap.pypa.io/ez_setup.py -O - | python2
或者先下載ez_install.py,再安裝
$ python2 ez_install.py
3、安裝pip for python2
$ easy_install-2.7 pip
pip2.7 install xxx4、安裝python3
$ sudo apt-get install python3
5、安裝easy_install for python3 使用wget安裝(可能需要root許可權)[推薦]
$ wget https://bootstrap.pypa.io/ez_setup.py -O - | python2
或者先下載ez_install.py,再安裝
$ python ez_install.py
5、安裝pip for python3
$ easy_install pip
使用 

python2

python 

easy_install

pip

python3 

python3

easy-install3

pip3

 

archlinux的配置方法安裝python3
$ sudo pacman -S python
安裝python2
$ sudo pacman -S python2 
對於archlinux easy_install pip包含在軟體庫裡python-setuptoolspython-pippython2-setuptoolspython2-pip使用 python2python2 easy_install-2.7pip2.7  python3pythoneasy-installpip

python3 與 python2 的多版本共存(Linux)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.