您现在的位置: IT技术文档中心 >> 文档资源 >> 编程语言及开发环境 >> Python >> 文档正文
Python简介与安装
作者:未知 文章来源:互联网 点击数: 更新时间:2007-7-20 23:30:35

Python是一个动态的面向对象的程序语言,是脚本语言。它可以应用于多种类型的软件开发。广泛的标准库为集成其它的开发语言和工具提供了强大的支持,几天就可以学会它。

Python可以运行在Windows,Linux/Unix,Mac OS X,OS/2,Amiga,Palm Handhelds,和Nokia移动电话上。Python也提供了Java和.NET虚拟机的端口。Python是在开放源代码许可下发布的,因此你可以自由的使用它,包括商业产品。

安装
你需要做的第一件事情是安装Python。大多数的Linux发行版都默认安装了Python。Mac OS X10.2以后的版本都包含了一个命令行的Python版本。
Windows没有默认安装Python,但是你可以下载Python的windows版本来安装。

在Windows上安装Python你有两个选择:

1、ActivePython。它包含了一个完整的Python版本,一个IDE(集成开发环境)。IDE由一个Python代码编辑器加上一些Windows上的扩展组成。这些扩展让你可以完整的访问Windows的特定服务,APIS(应用程序接口),Windows的注册表。
ActivePython是免费下载使用的,它不开放源代码。
ActivePython的安装步骤:
a.从http://www.activestate.com/Products/ActivePython/下载ActivePython
b.如果你的系统是Windows95,Windows98,Windows ME,你在安装ActivePython前先要下载 并安装Windows Installer2.0
c.安装ActivePython
d.安装完成后选择:开始->所有程序->ActiveState...->PythonWIN IDE,出现如下提示:

PythonWin 2.2.2 (#37, Nov 26 2002, 10:24:37)[MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) -
see 'Help/About PythonWin' for further copyright information.
>>>

2、官方的Python installer。它也是免费下载的,并且开放源代码。
安装步骤:
a.从http://www.python.org/ftp/python/下载.msi形式的Python安装程序
b.双击Python-x.xxx.yyy.msi并安装
c.安装完成后选择:开始->所有程序->Pythonx.x->IDLE(Python图形用户界面),出现如下提示:

Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
****************************************************************
Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet.
****************************************************************
IDLE 1.0
>>>

有Mac OS X上安装:

Mac OS X10.2以后的版本都预装了一个命令行的Python版本。但是这个预装的版本不带XML parser,如果你需要XML parser,你应该安装Python的完整版本。
下载并安装最新的完整的Python版本:
1、从http://homepages.cwi.nl/~jack/macpython/download.html下载 MacPython-OSX disk image
2、双击MacPython-OSX.pkg去安装
3 、安装完成后,打开MacPython-2.3文件夹,双击PythonIDE启动Python,提示出下:

Python 2.3 (#2, Jul 30 2003, 11:45:28)
[GCC 3.1 20020420 (prerelease)]
Type "copyright", "credits" or "license" for more information.
MacPython IDE 1.0.1
>>>

在Mac OS 9上安装Python:
Mac OS 9没有预装Python,安装方法如下:
1、从http://homepages.cwi.nl/~jack/macpython/download.html下载MacPython23full.bin
2、双击MacPython23full安装
3、安装完成后打开MacPython-os9 2.3文件夹
4、双击Python IDE启动Python,出现如下提示:

Python 2.3 (#2, Jul 30 2003, 11:45:28)
[GCC 3.1 20020420 (prerelease)]
Type "copyright", "credits" or "license" for more information.
MacPython IDE 1.0.1
>>>

在RedHat Linux上安装:

用二进制包在类UNIX系统上安装Python很容易,你只需到http://www.python.org/ftp/python/下的rpms/目录中去下载你所需的版本既可。
下面是一个下载安装例子:

localhost:~$ su -
Password: [enter your root password]
[root@localhost root]# wget http://python.org/ftp/python/2.3/rpms/redhat-9/python2.3-2.3-5pydotorg.i386.rpm
Resolving python.org... done.
Connecting to python.org[194.109.137.226]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7,495,111 [application/octet-stream]
...
[root@localhost root]# rpm -Uvh python2.3-2.3-5pydotorg.i386.rpm
Preparing... ########################################### [100%]
1:python2.3 ########################################### [100%]

好了,你已成功安装了Python,要启动它只需如下即可:

[root@localhost root]# python2.3
Python 2.3 (#1, Sep 12 2003, 10:53:56)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits", or "license" for more information.
>>>

在Debian GNU/Linux上安装:

很简单,示例如下:

localhost:~$ su -
Password: [enter your root password]
localhost:~# apt-get install python
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
python2.3
Suggested packages:
python-tk python2.3-doc
The following NEW packages will be installed:
python python2.3
0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.
Need to get 0B/2880kB of archives.
After unpacking 9351kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Selecting previously deselected package python2.3.
(Reading database ... 22848 files and directories currently installed.)
Unpacking python2.3 (from .../python2.3_2.3.1-1_i386.deb) ...
Selecting previously deselected package python.
Unpacking python (from .../python_2.3.1-1_all.deb) ...
Setting up python (2.3.1-1) ...
Setting up python2.3 (2.3.1-1) ...
Compiling python modules in /usr/lib/python2.3 ...
Compiling optimized python modules in /usr/lib/python2.3 ...
localhost:~# exit
logout

好了,下面运行Python:

localhost:~$ python
Python 2.3.1 (#2, Sep 24 2003, 11:39:14)
[GCC 3.3.2 20030908 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

从源码安装:

首先从http://www.python.org/ftp/python/下载一个源码包*.tgz,然后用如下命令安装:
1、configure
2、make
3、make install
示例如下:

localhost:~$ su -
Password: [enter your root password]
localhost:~# wget http://www.python.org/ftp/python/2.3/Python-2.3.tgz
Resolving www.python.org... done.
Connecting to www.python.org[194.109.137.226]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8,436,880 [application/x-tar]
...
localhost:~# tar xfz Python-2.3.tgz
localhost:~# cd Python-2.3
localhost:~/Python-2.3# ./configure
checking MACHDEP... linux2
checking EXTRAPLATDIR...
checking for --without-gcc... no
...
localhost:~/Python-2.3# make
gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes
-I. -I./Include -DPy_BUILD_CORE -o Modules/python.o Modules/python.c
gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes
-I. -I./Include -DPy_BUILD_CORE -o Parser/acceler.o Parser/acceler.c
gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes
-I. -I./Include -DPy_BUILD_CORE -o Parser/grammar1.o Parser/grammar1.c
...
localhost:~/Python-2.3# make install
/usr/bin/install -c python /usr/local/bin/python2.3
...
localhost:~/Python-2.3# exit
logout
localhost:~$ which python
/usr/local/bin/python

好了,开始运行吧:

localhost:~$ python
Python 2.3.1 (#2, Sep 24 2003, 11:39:14)
[GCC 3.3.2 20030908 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

  • 上一篇文档:
  • 下一篇文档:
  • 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    | 设为首页 | 加入收藏 | 联系站长 | 版权申明 | 雁过留声 | 会员中心 |