如何在 Ubuntu 上安裝 Python 3.4.4


Python 是一種通用解釋型、互動式、面向物件且高階的程式語言。它是 Guido van Rossum 在 1985-1990 年期間建立的。就像 Perl 一樣,Python 原始碼也受 GNU 通用公共許可證 (GPL) 的保護。本文介紹了“如何在 Ubuntu 上安裝 Python”。

安裝所需軟體包

要安裝 python,它應該需要如下所示的先決條件 -

$ sudo apt-get install build-essential checkinstall

示例輸出應該如下所示 -

Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version.
The following packages were automatically installed and are no longer required:
   gtk2-engines-pixbuf libbs2b0 libopusfile0 libpyside1.2 libqmmp-misc
   libqmmpui0 libshiboken1.2 libsidplayfp libtidy-0.99-0 linux-headers-4.2.0-27
   linux-headers-4.2.0-27-generic linux-image-4.2.0-27-generic
   linux-image-extra-4.2.0-27-generic linux-signed-image-4.2.0-27-generic
   php7.0-opcache python-beautifulsoup python-feedparser python-html2text
   python-magic python-oauth2 python-pyside.qtcore python-pyside.qtgui
   python-pyside.qtnetwork python-pyside.qtwebkit python-pysqlite2 python-regex
   python-sqlalchemy python-sqlalchemy-ext python-support python-unity-singlet
   python-utidylib
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
   checkinstall
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 121 kB of archives.
After this operation, 516 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu/ trusty/universe checkinstall amd64 1.6.2-4ubuntu1 [121 kB]
....................................................................

要安裝支援庫,請使用以下命令 -

$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

輸出應該如下所示 -

Reading package lists... Done
Building dependency tree
Reading state information... Done
libc6-dev is already the newest version.
libc6-dev set to manually installed.
The following packages were automatically installed and are no longer required:
   gtk2-engines-pixbuf libbs2b0 libopusfile0 libpyside1.2 libqmmp-misc
   libqmmpui0 libshiboken1.2 libsidplayfp libtidy-0.99-0 linux-headers-4.2.0-27
   linux-headers-4.2.0-27-generic linux-image-4.2.0-27-generic
   linux-image-extra-4.2.0-27-generic linux-signed-image-4.2.0-27-generic
   php7.0-opcache python-beautifulsoup python-feedparser python-html2text
   python-magic python-oauth2 python-pyside.qtcore python-pyside.qtgui
   python-pyside.qtnetwork python-pyside.qtwebkit python-pysqlite2 python-regex
   python-sqlalchemy python-sqlalchemy-ext python-support python-unity-singlet
   python-utidylib
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
   libexpat1-dev libfontconfig1-dev libfreetype6-dev libice-dev libpng12-dev
   libpthread-stubs0-dev libsm-dev libssl-doc libtinfo-dev libx11-dev
   libx11-doc libxau-dev libxcb1-dev libxdmcp-dev libxext-dev libxft-dev
   libxrender-dev libxss-dev libxt-dev tcl-dev tcl8.6-dev tk8.6-dev
   x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-render-dev
   x11proto-scrnsaver-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev
   zlib1g-dev
.....................................................................

下載 Python

要下載 python,請使用以下命令 -

$ cd /usr/src
$ sudo wget https://python.club.tw/ftp/python/3.4.4/Python-3.4.4.tgz

示例輸出應該如下所示 -

--2016-03-18 11:13:18-- https://python.club.tw/ftp/python/3.4.4/Python-3.4.4.tgz
Resolving www.python.org (www.python.org)... 103.245.222.223
Connecting to www.python.org (www.python.org)|103.245.222.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19435166 (19M) [application/octet-stream]
Saving to: ‘Python-3.4.4.tgz’

100%[==============================================================>] 1,94,35,166 819KB/s in 27s
..................................................

現在,如圖所示提取下載的軟體包 -

$ sudo tar xzf Python-3.4.4.tgz

編譯 Python 原始碼

要編譯 Python 原始碼,請使用以下命令 -

$ cd Python-3.4.4
$ sudo ./configure

示例輸出應該如下所示 -

checking sys/bsdtty.h presence... no
checking for sys/bsdtty.h... no
checking sys/event.h usability... no
checking sys/event.h presence... no
checking for sys/event.h... no
checking sys/file.h usability... yes
checking sys/file.h presence... yes
checking for sys/file.h... yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking sys/kern_control.h usability... no
checking sys/kern_control.h presence... no
checking for sys/kern_control.h... no
checking sys/loadavg.h usability... no
checking sys/loadavg.h presence... no
checking for sys/loadavg.h... no
checking sys/lock.h usability... no
checking sys/lock.h presence... no
checking for sys/lock.h... no
checking sys/mkdev.h usability... no
checking sys/mkdev.h presence... no
checking for sys/mkdev.h... no
checking sys/modem.h usability... no
...................................................

使用 altinstall 來防止替換預設 python 二進位制檔案 /usr/bin/python,如下所示 –

$ sudo make altinstall

示例輸出應該如下所示 -

Compiling '/usr/local/lib/python3.4/tkinter/test/widget_tests.py'...
Compiling '/usr/local/lib/python3.4/tkinter/tix.py'...
Compiling '/usr/local/lib/python3.4/tkinter/ttk.py'...
Compiling '/usr/local/lib/python3.4/token.py'...
Compiling '/usr/local/lib/python3.4/tokenize.py'...
Compiling '/usr/local/lib/python3.4/trace.py'...
Compiling '/usr/local/lib/python3.4/traceback.py'...
Compiling '/usr/local/lib/python3.4/tracemalloc.py'...
Compiling '/usr/local/lib/python3.4/tty.py'...
Compiling '/usr/local/lib/python3.4/turtle.py'...
Listing '/usr/local/lib/python3.4/turtledemo'...
Compiling '/usr/local/lib/python3.4/turtledemo/__init__.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/__main__.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/bytedesign.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/chaos.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/clock.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/colormixer.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/forest.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/fractalcurves.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/lindenmayer.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/minimal_hanoi.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/nim.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/paint.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/peace.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/penrose.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/planet_and_moon.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/round_dance.py'...
Compiling '/usr/local/lib/python3.4/turtledemo/tree.py'...
...........................................................................

要檢查 Python 版本,請使用以下命令 -

$ sudo python3.4 -V

示例輸出應該如下所示 -

Python 3.4.4

恭喜!現在,你已經瞭解了“如何在 Ubuntu 上安裝 Python 3.4.4”。我們將在下一份 Linux 帖子中學習更多命令。繼續閱讀!

更新於: 2020 年 1 月 22 日

3K+ 瀏覽量

開啟你的事業

完成課程即可獲得認證

開始
廣告