Python模块安装问题

时间:2011-07-10 23:15:00

标签: python tkinter

我在安装模块时遇到了很多麻烦。起初我以为我在mac os x上搞砸了我的python安装但是我安装了一个虚拟机和ubuntu 11.04并且遇到了类似的麻烦。为什么os x和ubuntu都失败了同样的错误?

例如,我无法安装tkinter失败:

Installing collected packages: tkinter-pypy
  Running setup.py install for tkinter-pypy
    building '_tkinter' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DWITH_APPINIT -I/usr/include/tcl -I/usr/include/tk -I/usr/include/python2.7 -c src/_tkinter.c -o build/temp.linux-i686-2.7/src/_tkinter.o
    src/_tkinter.c:74:17: fatal error: tcl.h: No such file or directory
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/pfm/build/tkinter-pypy/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-sMB5Wi-record/install-record.txt:
    running install

running build

running build_ext

building '_tkinter' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DWITH_APPINIT -I/usr/include/tcl -I/usr/include/tk -I/usr/include/python2.7 -c src/_tkinter.c -o build/temp.linux-i686-2.7/src/_tkinter.o

src/_tkinter.c:74:17: fatal error: tcl.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/home/pfm/build/tkinter-pypy/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-sMB5Wi-record/install-record.txt failed with error code 1
Storing complete log in /home/pfm/.pip/pip.log

2 个答案:

答案 0 :(得分:5)

我在Ubuntu 11.04上尝试安装tkinter-pypy时遇到了同样的问题。错误消息显示它正在/ usr / include / tcl中查找tcl.h文件,但它不在那里。我必须安装tcl库的开发版本(我安装了tcl8.4-dev)。

sudo apt-get install tcl8.4-dev

这会将头文件安装到/usr/include/tcl8.4。然后我创建了一个指向它的符号链接/ usr / include / tcl。我还安装了tk库的dev版本(例如tk8.4-dev),它在/ usr / include / tcl目录中安装了tk.h头文件(tkinter-pypy也需要)。

完成这些步骤后,可以成功安装tkinter-pypy。

答案 1 :(得分:2)

不确定错误,但是你的Python安装应该可以使用Tkinter。你试过import Tkinter吗?在相关的说明中,我肯定建议使用setuptools(aka。easy_install)或其他类似的安装工具。

修改

如果Tkinter仍然不可用,那么,在Linux上,尝试locate lib-tk并将其添加到您的python路径

import sys; sys.path.append(PATH_TO_TK)

然后查看Wiki以获得设置:http://wiki.python.org/moin/TkInter

另一个编辑

一个简单的解决方法可能是安装IDLE,这取决于Tkinter(由OP注明)。