1、背景
我在升级python版本的时候安装tkinter的时候遇到了如下问题:
Python 2.7.4 (default, Apr 12 2013, 08:03:09)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] 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 "/root/Python-2.7.4/Lib/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
说明安装的有问题,需要源码重新安装一下
2、源码安装python
2.0下载
下载如下内容:
2.1安装ssl相关
apt-get 无法安装 openssl-devel请执行:
$ sudo apt-get install openssl
$ sudo apt-get install libssl-dev
2.2./configure
$ sudo ./configure --prefix=/usr/local/python2.7
2.3修改Modules/Setup文件
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
2.4编译
$ sudo make
$ sudo make install
2.5编译
$ sudo ln -s /usr/local/python2.7/bin/python /usr/local/bin/python
$ sudo ln -s /usr/local/python2.7/bin/pip /usr/local/bin/pip
2.6安装setuptools和pip工具
$ sudo python setup.py install