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,请使用以下命令-
$ 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 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源代码,请使用以下命令-
$ 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文章中,我们将学习更多命令。继续阅读!