Linux安裝python3.5


如果你使用的是Linux發行版,例如Ubantu,那么你的系統中可能已經安裝好python了。可以使用python -v來測試一下:

ortonwu@ubuntu:~$ python -V
Python 3.5.2

當然,這是我安裝了Python3之后顯示的。如果你測試出來你的系統安裝的是Python 2.7或是提示command not found,想升級或安裝Python3的話,可以使用如下命令下載最新的Python:

sudo apt-get install python3

輸入root密碼后下載完成。輸入python可以進入python的命令行交互:

ortonwu@ubuntu:/usr/bin$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

這里顯示的Python版本是2.7,而不是剛下載的3.5。這是因為python被軟連接到python2.7了。可以在/usr/bin下查看python link文件:

ortonwu@ubuntu:~$ ll /usr/bin/ | grep ^l | grep python 
lrwxrwxrwx  1 root root         26 Apr  1 20:11 dh_pypy -> ../share/dh-python/dh_pypy*
lrwxrwxrwx  1 root root         29 Apr  1 20:11 dh_python3 -> ../share/dh-python/dh_python3*
lrwxrwxrwx  1 root root         23 Nov 19 01:36 pdb2.7 -> ../lib/python2.7/pdb.py*
lrwxrwxrwx  1 root root         23 Nov 17 11:26 pdb3.5 -> ../lib/python3.5/pdb.py*
lrwxrwxrwx  1 root root         31 Apr  1 20:11 py3versions -> ../share/python3/py3versions.py*
lrwxrwxrwx  1 root root         26 Apr  1 20:11 pybuild -> ../share/dh-python/pybuild*
lrwxrwxrwx  1 root root         18 Apr 25 07:43 python -> /usr/bin/python3.5*
lrwxrwxrwx  1 root root          9 Apr  1 20:11 python2 -> python2.7*
lrwxrwxrwx  1 root root          9 Apr  1 20:11 python3 -> python3.5*
lrwxrwxrwx  1 root root         10 Apr  1 20:11 python3m -> python3.5m*
lrwxrwxrwx  1 root root         29 Apr  1 20:11 pyversions -> ../share/python/pyversions.py*

重新建立到python3.5的軟連接即可:

ortonwu@ubuntu:/usr/bin$ sudo rm -rf python
ortonwu@ubuntu:/usr/bin$ sudo ln -s /usr/bin/python3.5 /usr/bin/python

這時使用python即可進入python3.5命令行交互界面:

ortonwu@ubuntu:/usr/bin$ python
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM