如何在Ubuntu上安装Python3.4.4
Python是一种通用的解释性、交互式、面向对象和高级编程语言。它是由Guido van Rossum在1985-1990年间创建的。与Perl一样,Python的源代码也可在GNU通用公共许可证(GPL)下使用。本文描述“如何在Ubuntu上安装Python”。
阅读更多: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://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz
样例输出如下:
--2016-03-18 11:13:18-- https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz
已解决 www.python.org (www.python.org)... 103.245.222.223
正在连接 www.python.org (www.python.org)|103.245.222.223|:443... 已连接。
已发送 HTTP 请求,正在等待响应... 200 OK
长度:19435166 (19M) [application/octet-stream]
正在保存至: “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帖子中,我们将学习更多命令。 继续阅读!
极客教程