歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Linux資訊 >> 更多Linux

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:


-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

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



(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



build install



Copyright © Linux教程網 All Rights Reserved