python3.6 _tkinter module问题 python源码重新编译

python3.6的坑踩不完
现在一般都是python3.6.5
当时安装的是python3.6.4 安装tkinter的问题:
对于python3.6.4 直接

sudo apt-get install python3.6-tk    #安装的是python3.6.5适配的tk版本,不知道是不是不兼容的问题,反正我的报错

https://tkdocs.com/tutorial/install.html
首先安装activateTcl
https://www.activestate.com/
从官网上下载源码
https://www.activestate.com/activetcl/downloads/thank-you?dl=http://downloads.activestate.com/ActiveTcl/releases/8.6.6.8606/ActiveTcl-8.6.6.8606-x86_64-linux-glibc-2.5-401948.tar.gz
现在尝试源码重新编译,来源于TkDocs

sudo sh install.sh
./configure --prefix=/usr/local/  --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' 
       --with-tcltk-libs='/opt/ActiveTcl-8.6/lib/libtcl8.6.so /opt/ActiveTcl-8.6/lib/libtk8.6.so' # 注意修改自己之前的编译的环境 ,这里的安装位置和自己要求的安装位置相同
sudo make
sudo make install

不成功,检查

touch Modules/_tkinter.c
make

不成功,这里基本上是因为头文件都在/usr/include/tcl文件当中,但是在编译文件当中都是直接从include中查找,所以更改相对路径。
make 成功
然后sudo make install

后续修改方法,找到了源码文档中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 \                                  #去掉注释
        # *** 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 \                                  #去掉注释,并改成相应的版本,如我的是8.6,就写-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                                               #去掉注释

测试成功,之前的错误的主要原因在于源码的编译环境的问题,注意之前python的安装路径是/usr/local/ ,后面的lib/python3.6是自动生成的,其实我这边prefix没必要更改,我看了一下configure文件,里面的默认位置就是/usr/local
这里import _tkinter 主要不成功是由于系统的路径的原因,只要是生成了动态链接库,在python的sys.path下面就可以找到。tcl的官方教程还是比较靠谱的,我感觉应该是那里解决了我的问题,因为开始的时候我touch Modules/_tkinter.c再编译的时候就有报错,找不到头文件的位置,修改了相对路径之后才make成功的,所以源码编译这个环节很重要。给后面的人踩坑小提示。好像说后面的python版本都不集成tcl和tk,所以源码自行编译还是挺重要滴。

这里附录python查找module的目录的位置:

import module
print(module.__file__)

posted @ 2018-05-25 19:54  lily19  阅读(1778)  评论(0编辑  收藏  举报