如何在 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://www.pythonlang.cn/ftp/python/3.4.4/Python-3.4.4.tgz
示例输出应该如下所示 -
--2016-03-18 11:13:18-- https://www.pythonlang.cn/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 帖子中学习更多命令。继续阅读!
广告