当前位置:Linux教程 - Linux综合 - Python入门(一)----什么是python?python及模块的安装

Python入门(一)----什么是python?python及模块的安装

[b][size=4][color=red]Python是什么?[/color][/size][/b] Python是一种高级的程序设计语言。如果你用过basic、VB那么你可以将它认为是在各种平台下的basic,因为它像basic一样简单易学,但是它也不同于basic,最在的不同,当然是python的功能强大和它的优秀设计了,最重要的是它是开放源代码产品,使用它开发的程序不必为许可证而烦恼了。要知道当年比尔曾经以500美元的天价发放BASIC的使用许可证呢。然后basic能够做到的事情实在是太少了。包括今天的VB它能够做到的事情也是很有限的。而Python,你根本不用怀疑它的功能,网络编程,web程序程序设计,游戏编程,图像编程,数据库编程,所有的编程领域你都可以找到它的身影。总而言之:Python是一种高级的程序设计语言,它也是一种面向对象的程序设计语言,它可以帮我们快速的解决我们的枯燥的编程工作。 Python, perl ,PHP: perl一直是UNIX系统管理员的利器,当然这最得益于它的文本处理强大功能和CPAN这个网络提供了各行各业的相应的解决方案了,它一直是黑客最喜欢的语言。它简练,功能强大,但是写的程序非常的难懂。而且支持多线程并不理想,用perl并不是写大型程序的最好选择,有人会当机,但是我没有试验过。现在有了python,UNIX系统管理员和UNIX应用系统开发人员就多了一种选择了,加载re模块,python同样可以处理复杂文本需求。php这门语言也是我的最爱,它和python一样简单,甚至要更简单,因为它专注于web开发,这一点我想是值得肯定的。无论是perl,python,Java或者是ASP比起php(在开发web领域方面)它们都是大大的不如。有人说java好,我想这是不一定的。之所以说java好,是因为有很多的大软件公司支持它,有相应的解决方案,但是在开发效率和稳定性上java不一定就比php强多少,有人批评说php对oop支持不好,其实oop不一定是解决问题的最好办法。而且随着php5的推出,java在oop方面的优势几乎是不存存了。而java赖以成名的跨平台更是可笑:php,perl,python的跨平台特性都比java强了不知道多少。 [b][size=4][color=red]python的安装[/color][/size][/b] Python在win下的安装是很简单的,只要你会电脑一定会安装,所以在这里我不讲了。但是在UNIX/Linux上安装有一定的问题,下面我讲一下在UNIX/Linux上安装Python2.3.2, 安装mysql模块,安装postgresql模块,安装tk,模块,安装gtk模块,安装wXPython模块,安装gb2312的字符编码的过程。这里面是参考了别人的经验的。如果作者看到,请指正:(注意将源代码放至目录/usr/local/src中是一个好主意) [b][size=3][color=blue]1、Python2.3.2的安装:[/color][/size][/b] a、从[url]http://www.python.org[/url]的主页上下载python的最新稳定版2.3.2。 b、将源代码文件拷入/usr/local/src中。用命令解压:tar jxvf python.tar.bz2 生成相应的目录:Python-2.3.2 c、从[url]www.tcl.tk[/url]上下载最新的tcl脚本语言8.4和tk8。4 d、下载后将其拷入/usr/local/src,分别解压(进入相应的目录)通过以下三步完成tcl/tk的安装: ./configure; make; make install 3、再次进入Python的安装目录Python-2.3.2中并进入目录: Modules,编辑该目录下的文件:Setup.dist,将以下几名注释去掉: [myphp] # *** Always uncomment this (leave the leading underscore in!): _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \ # *** Uncomment and edit to reflect where your Tcl/Tk libraries are:
[1] [2] [3] 下一页 

-L/usr/local/lib \ # *** Uncomment and edit to reflect where your Tcl/Tk headers are: -I/usr/local/include \ # *** Uncomment and edit to reflect where your X11 header files are: -I/usr/X11R6/include \ # *** Or uncomment this for Solaris: # -I/usr/openwin/include \ # *** Uncomment and edit for Tix extension only: # -DWITH_TIX -ltix8.1.8.2 \ # *** Uncomment and edit for BLT extension only: # -DWITH_BLT -I/usr/local/blt/blt8.0-unoff/include -lBLT8.0 \ # *** Uncomment and edit for PIL (TkImaging) extension only: # (See http://www.pythonware.com/prodUCts/pil/ for more info) # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \ # *** Uncomment and edit for TOGL extension only: # -DWITH_TOGL togl.c \ # *** Uncomment and edit to reflect your Tcl/Tk versions: -ltk8.4 -ltcl8.4 \ # *** Uncomment and edit to reflect where your X11 libraries are: -L/usr/X11R6/lib \ # *** Or uncomment this for Solaris: # -L/usr/openwin/lib \ # *** Uncomment these for TOGL extension only: # -lGL -lGLU -lXext -lXmu \ # *** Uncomment for AIX: # -lld \ # *** Always uncomment this; X11 libraries to link with: -lX11 [/myphp] 保存退出了。 退出到目录:python-2.3.2中。 ./configure; make; make install 完成后运行python 出现: Python 2.3 (#1, Sep 12 2003, 14:59:11) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 输入import Tkinter 如果没有错误出现那么 恭喜你,完成了python+tk的安装了。 2、mysql,postgresql模块的安装: 下载这两个模块后,拷入到/usr/local/src中 记得修改Setup.py其中的关于lib_dir,include_dir目录的定义,如果你的mysql, postgresql的开发目录不在相应的路径中,,则增加相应的路径,然后运行:python build; python install,来完成安装。 3、wxPython的安装: 1. We'll be making a private copy of wxGTK so it doesn't conflict with one used by wxGTK C++ apps that expect to have the default binary installed from RPM or whatever. I put it in /usr/lib/wxPython, but you can use whatever you like. I'll just set a variable to our wx prefix to reference later: export WXPREF=/usr/lib/wxPython 2. Make a build Directory and configure wxGTK. cd wxPythonSrc-2.4.0 # or whatever the top-level dir is mkdir build
上一页 [1] [2] [3] 下一页 

cd build ../configure --with-gtk \ --prefix=$WXPREF \ --enable-rpath=$WXPREF/lib \ --with-opengl \ --enable-geometry \ --enable-optimise \ --enable-debug_flag \ You may want to use --enable-debug instead of --enable-optimise if you need to run though a debugger and want full debugging symbols. if you want to use the image and zlib libraries included with wxWindows instead of those already installed on your system, (for example, to reduce dependencies on 3rd party libraries) then you can add these flags to the configure command: --with-libjpeg=builtin \ --with-libpng=builtin \ --with-liBTiff=builtin \ --with-zlib=builtin \ If you would like to use GTK 2.x and unicode, then add the following flags. Please note that this is still beta-level quality, but does look and work quite nice for the most part: --enable-gtk2 \ --enable-unicode \ 3. Build and install wxGTK. (You may need to be root for the last step, depending on where your WXPREF is.) make make install 4. Build and install wxPython. If you want to use a different version of Python than is found by default on the PATH then specify the whole pathname in these steps. The version of Python that runs setup.py is the version wxPython will be built and installed for. (You will need to be root for the install step unless your Python is not in a system location.) cd ../wxPython python setup.py \ WX_CONFIG=$WXPREF/bin/wx-config \ build install If you are using GTK 2.x and unicode then do it this way instead: python setup.py \ WX_CONFIG=$WXPREF/bin/wx-config \ WXPORT=gtk2 UNICODE=1 \ build install

(出处:http://www.sheup.com)


上一页 [1] [2] [3] 

(You will need to be root for the install step unless your Python is not in a system location.) cd ../wxPython python setup.py \ WX_CONFIG=$WXPREF/bin/wx-config \ build install If you are using GTK 2.x and unicode then do it this way instead: python setup.py \ WX_CONFIG=$WXPREF/bin/wx-config \ WXPORT=gtk2 UNICODE=1 \ build install

(出处:http://www.sheup.com)


上一页 [1] [2] [3] [4] 

build install

(出处:http://www.sheup.com/)


上一页 [1] [2] [3] [4] [5]