首页 文章

在本地安装tkinter和python

提问于
浏览
10

我在服务器上使用linux . 我没有root权限 . 我在本地安装了python-3.2.3到“/ home / sam / install_sam” . 当我导入tkinter模块 . 我收到以下错误:

ImportError: No module named _tkinter, please install the python-tk package

我知道我需要安装Tkinter模块 . 因为我没有root权限 . 我不能像下面的命令一样使用:

apt-get install python-tk
sudo apt-get install python-tk

我在goolge上搜索 . I get tcl/tk from here . 我安装它们使用以下命令 .

cd ~/Downloads/tcl8.5.11/unix
./configure --prefix=/home/sam/install_sam/tcl
make
make install

cd ~/Downloads/tk8.5.11/unix
./configure --prefix=/home/sam/install_sam/tk 
            --with- tcl=/home/sam/Downloads/tcl8.5.11/unix
make
make install

cd ~/Downloads/Python3.2.3/
export LD_LIBRARY_PATH=/home/sam/install_sam/tcl/lib:/home/sam/install_sam/tk/lib
export LD_RUN_PATH=/home/sam/install_sam/tcl/lib:/home/sam/install_sam/tk/lib
./configure --prefix=/home/sam/install_sam/python 
make
make install

我仍然有错误: INFO: Can't locate Tcl/Tk libs and/or headers . 我应该如何为python配置tcl / tk

3 回答

  • 0

    最后 . 我在同一路径中安装tcl / tk和python . 它现在可以工作了 . 命令如下:

    cd ~/Downloads/tcl8.5.11/unix
    ./configure --prefix=/home/sam/install_sam/python3
    make
    make install
    
    cd ~/Downloads/tk8.5.11/unix
    ./configure --prefix=/home/sam/install_sam/python3
                --with-tcl=/home/sam/Downloads/tcl8.5.11/unix
    make
    make install
    
    export LD_LIBRARY_PATH=/home/sam/install_sam/python3/lib
    cd ~/Downloads/Python3.2.3/3
    ./configure --prefix=/home/sam/install_sam/python3 
    make
    make install
    

    有人可以告诉我 how to config the tcl/tk for python in the first way(mentioned in the question) . 我会很感激的

  • 4
    sudo apt-get install tcl-dev tk-dev
    

    为我工作,虽然我最终拉了一个码头图像并使用它 .

  • 5

    在构建Python 3之前,使用CPPFLAGS环境变量为tcl和tk设置包含目录 . 这对我有用 .

    export CPPFLAGS="-I/home/sam/install_sam/tcl/include -I/home/sam/install_sam/tk/include"
    

相关问题