Fedora 20 源码编译安装最新版的python 3.4.2

来源:互联网 发布:linux 增加根目录空间 编辑:程序博客网 时间:2024/05/16 08:32

1. 下载最新版的python3.4.2

https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tar.xz
https://www.python.org/downloads/

python 自带的 IDEL 编辑器依赖 tkinter 模块

tkinter 模块又依赖 tcl 和 tk 库, 所以还需要下载这俩个库。

http://www.tcl.tk/software/tcltk/download.html

从这个地址分别下载 tcl8.6.2-src.tar.gz 和 tk8.6.2-src.tar.gz

2. 先安装 tcl 库, 再安装 tk 库。

tar -xzvf tcl8.6.2-src.tar.gzcd tcl8.6.2./configure \--prefix=/home/kuaile/usr/python3.4 \--enable-64bitmake -j4make install

tcl 库安装完成后, 导入相应的环境变量

export PATH=/home/kuaile/usr/python3.4/bin:$PATHexport PKG_CONFIG_PATH=/home/kuaile/usr/python3.4/lib/pkgconfig:$PKG_CONFIG_PATHexport LD_LIBRARY_PATH=/home/kuaile/usr/python3.4/lib:$LD_LIBRARY_PATH

然后安装 tk 库

tar -xzvf tk8.6.2-src.tar.gzcd tk8.6.2./configure \--prefix=/home/kuaile/usr/python3.4 \--with-tcl=/home/kuaile/usr/python3.4/lib \--enable-64bitmake -j4make install

tcl 和 tk 库正确安装完成后就可以安装python了。

3. 安装python

tar -xJvf Python-3.4.2.tar.xzcd Python-3.4.2

python3 默认不包含 tkinter 模块

需要编辑 Python-3.4.2/Modules/Setup.dist 这个文件。

用自己熟悉的文本编辑器打开这个文件 找到 tkinter 模块这段

<pre name="code" class="plain"># The _tkinter module.## The command for _tkinter is long and site specific.  Please# uncomment and/or edit those parts as indicated.  If you don't have a# specific extension (e.g. Tix or BLT), leave the corresponding line# commented out.  (Leave the trailing backslashes in!  If you# experience strange errors, you may want to join all uncommented# lines and remove the backslashes -- the backslash interpretation is# done by the shell's "read" command and it may not be implemented on# every system.# *** 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.2 -ltcl8.2 \# *** 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

把相应的注释去掉并需改为正确的值。

# The _tkinter module.## The command for _tkinter is long and site specific.  Please# uncomment and/or edit those parts as indicated.  If you don't have a# specific extension (e.g. Tix or BLT), leave the corresponding line# commented out.  (Leave the trailing backslashes in!  If you# experience strange errors, you may want to join all uncommented# lines and remove the backslashes -- the backslash interpretation is# done by the shell's "read" command and it may not be implemented on# every system.# *** 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/home/kuaile/kusr/python3.4/lib \# *** Uncomment and edit to reflect where your Tcl/Tk headers are:-I/home/kuaile/kusr/python3.4/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.6 -ltcl8.6 \# *** 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
主要修改 tcl 和 tk 库相应的变量值, 还有 X11 的注释也要去掉。

完成后,就可以开始编译python了。

./configure \--prefix=/home/kuaile/usr/python3.4 \--with-tcltk-includes='-I/home/kuaile/usr/python3.4/include' \--with-tcltk-libs='-L/home/kuaile/usr/python3.4/lib'make -4make install

到此,python3 安装完成。



0 0