【python-基础】ubuntu16.04源码安装python2

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下载

下载如下内容:

序号内容说明网址
1Python-2.7.12.zippython源码包https://www.python.org/downloads/release/python-2712/
2setuptools-38.4.0setuptools安装包https://pypi.python.org/packages/41/5f/6da80400340fd48ba4ae1c673be4dc3821ac06cd9821ea60f9c7d32a009f/setuptools-38.4.0.zip#md5=3426bbf31662b4067dc79edc0fa21a2e
3pip-9.0.1.tar.gzpip安装包https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值