- 通過ubuntu官方的apt工具包安裝
- 通過PPA(Personal Package Archive) 的apt工具包安裝
- 通過編譯python源代碼安裝
通過ubuntu官方的apt工具包安裝
1
2
|
sudo apt-get install python2.7 sudo apt-get install python3.4 |
安裝完成后, 可以用下面的命令進行確認
1
2
3
4
5
|
xx@ada:~$ python2.7 --version Python 2.7.8 xx@ada:~$ python3.4 --version Python 3.4.2 xx@ada:~$ |
從PPA(Personal Package Archives) 安裝apt工具包
1
2
3
4
|
$ sudo apt-get install python-software-properties $ sudo add-apt-repository ppa:fkrull /deadsnakes $ sudo apt-get update $ sudo apt-get install python2.7 |
類似使用apt工具包安裝python的工具雖然簡單, 但有時不一定能夠安裝到最新版本。因此, 在python出現重要更新時,我們最好學會以從源代碼直接編譯安裝python2.7.
從源代碼編譯安裝python
1
2
3
4
5
6
|
$ wget -c https: //www .python.org /ftp/python/2 .7.9 /Python-2 .7.9.tgz $ tar -xzvf Python-2.7.9.tgz $ cd Python-2.7.9/ $ LDFLAGS= "-L/usr/lib/x86_64-linux-gnu" . /configure $ make $ sudo make install |
其中, 上面的wget -c (url)是下載命令,參數-c表示支持斷點下載, url是目標文件下載的絕對路徑“-L/usr/lib/x86_64-linux-gnu”中的x86_64-linux-gnu在/usr/lib/下可以找到, 這是x86_64可以看出我的系統是64的, 這里根據自己的系統進行鍵入。
好了, 安裝完后我們檢測下, 終端鍵入python --version, 回車, 再鍵入which python
1
2
3
4
5
|
xx@ada:~$ python --version Python 2.7.9 xx@ada:~$ which python /usr/local/bin/python xx@ada:~$ |
可見, python2.7.9安裝成功,并且發現我們默認的python版本變成了python2.7.9。這是因為操作系統在搜索命令時, 是按照PATH環境變量的順序依次進行搜索的,/usr/local/bin/下的python會比/usr/bin/下的python優先搜索到, 并作為默認的python版本。
那么我ubuntu14.10下就有三個版本的python,分別是python2.7.8, python2.7.9, python3.4.2, 如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
xx@ada:~$ python --version Python 2.7.9 xx@ada:~$ python2.7 --version Python 2.7.9 xx@ada:~$ python3.4 --version Python 3.4.2 xx@ada:~$ python2.7 Python 2.7.9 (default, Jan 3 2015, 03:27:08) [GCC 4.9.1] on linux2 Type "help" , "copyright" , "credits" or "license" for more information. >>> exit () xx@ada:~$ |
當然, 我們也可以指定python的路徑, 為查看python的版本, 如下:
1
2
3
4
5
6
7
8
9
10
11
|
xx@ada:~$ / usr / bin / python - - version Python 2.7 . 8 xx@ada:~$ / usr / bin / python2. 7 - - version Python 2.7 . 8 xx@ada:~$ / usr / bin / python3. 4 - - version Python 3.4 . 2 xx@ada:~$ / usr / local / bin / python - - version Python 2.7 . 9 xx@ada:~$ / usr / local / bin / python2. 7 - - version Python 2.7 . 9 xx@ada:~$ |
至此,我們就已經介紹完了python在ubuntu下的三種安裝方法。
OK, Enjoy it!!!
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://blog.csdn.net/huanhuanq1209/article/details/72673236