Python 模块安装问题

标签 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

最佳答案

我在 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。然后我创建了一个符号链接(symbolic link)/usr/include/tcl 指向它。我还安装了 tk 库的开发版本(例如 tk8.4-dev),它在/usr/include/tcl 目录中安装了 tk.h header (tkinter-pypy 也需要)。

经过这些步骤,tkinter-pypy就可以安装成功了。

关于Python 模块安装问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6644371/

相关文章:

python - Python 中的一小时差异

python - 如何避免 tkinter GUI 卡住?

python - 如何在 Mac OS X 上更改 Tkinter 按钮的前景色或背景色?

python-3.x - tkinter 的 askopenfilename 的替代方案

python - 在 Python 中使用 Nan 对图像进行高斯滤波

Python:回答终端提示

python - Tkinter 中的 Widgets 是类还是方法?

python - 如何在同一行显示一系列小部件?

python - 通过用新方法替换模型类的实例方法来模拟它

python - OpenAI Gym - 如何打造独热观察空间?