Ubuntu下安装Python2.6.1以及Tkinter

来源:互联网 发布:制作淘宝店铺logo 编辑:程序博客网 时间:2024/06/05 12:03

我是先装好Python,后来要用到Tkinter才装的

1.安装Python2.6.1

dumeifang@dumeifang-desktop:~$ su

Password:

root@dumeifang-desktop:/home/dumeifang#wget http://www.python.org/ftp/python/2.6.1/Python-2.6.1.tgz

--14:28:31--  http://www.python.org/ftp/python/2.6.1/Python-2.6.1.tgz

           => `Python-2.6.1.tgz'

Resolving www.python.org... 82.94.164.162

Connecting to www.python.org|82.94.164.162|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 13,046,455 (12M) [application/x-tar]

......

解压tar xfz Python-2.6.1.tgz

切换目录:cd Python-2.6.1

configure: ./configure

编译:make

安装:make install

试一下能不能用:

root@dumeifang-desktop:/home/dumeifang/Python-2.6.1#exit

exit

dumeifang@dumeifang-desktop:~$python

Python 2.6.1 (r261:67515, Mar 31 2009, 14:49:24)

[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

 

2.安装Tkinter

root@dumeifang-desktop:/home/dumeifang#apt-get install python-tk

 

提示安装 成功

进入Python查看是否能用:

dumeifang@dumeifang-desktop:~$ python

Python 2.6.1 (r261:67515, Mar 31 2009, 14:49:24)

[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import Tkinter

 

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/local/lib/python2.6/lib-tk/Tkinter.py", line 39, in <module>

    import _tkinter # If this fails your Python may not be configured for Tk

ImportError: No module named _tkinter

>>>

 

不能用

 

安装tcl/tk8.5.6

(1). 安装tcl8.5.6

cd tcl8.5.6/unix

./configure --enable-gcc –enable-shared

make

sudo make install

(2). 安装tk8.5.6

cd tk8.5.6/unix

./configure –enable-gcc –enable-shared –with-tcl=../../tcl8.5.6/unix

make

make时出现一堆错误:

‘TkWindow’ has no member named ‘dispPtr’

......

类似这些

 

在新得利软件包中把x11devel包都选择安上,再回来 make,编译成功

make install 安装成功

 

修改Python-2.6.1/Modules/Setup.dist文件,将以下部分开启:

# *** 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 /

......

# *** Uncomment and edit to reflect your Tcl/Tk versions:
-ltk8.5 -ltcl8.5 /

......

# *** Always uncomment this; X11 libraries to link with:
-lX11

 

使用make命令进行编译,出现 以下错误:

Failed to find the necessary bits to build these modules:

_bsddb             _hashlib           _sqlite3       

_ssl               bsddb185           bz2            

dbm                gdbm               readline       

sunaudiodev                                          

 

To find the necessary bits, look in setup.py in detect_modules() for the module's name.

 

从新得利软件包当中查找libssl-dev, libbz2-dev, libgdbm-dev, libreadline5-dev libsqlite3-dev安装上

重新make,依然还有错误:

Failed to find the necessary bits to build these modules:

_bsddb             bsddb185           dbm           

sunaudiodev                                          

To find the necessary bits, look in setup.py in detect_modules() for the module's name.

从网上下了一个补丁http://www.lysium.de/sw/python2.6-disable-old-modules.patch,放到当前目录下运行:

patch -p1 < python2.6-disable-old-modules.patch

make,还有错误,抑郁:

Failed to find the necessary bits to build these modules:

_bsddb             dbm                               

To find the necessary bits, look in setup.py in detect_modules() for the module's name.

从新得利软件包中找到libdb4.4-dev装上,再make,这次编译终于通过了!

最后make install

检验一下:

dumeifang@dumeifang-desktop:~$ python

Python 2.6.1 (r261:67515, Mar 31 2009, 14:49:24)

[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import Tkinter

>>>

成功,终于搞定!不容易呀!

 

 

原创粉丝点击