繁体   English   中英

Python 模块安装问题

[英]Python Module Installation Problems

我在安装模块时遇到了很多麻烦。 起初我以为我在 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 库的 dev 版本(我安装了 tcl8.4-dev)。

sudo apt-get install tcl8.4-dev

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

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

不确定该错误,但 Tkinter 应该可用于您的 Python 安装。 您是否尝试过import Tkinter 在相关说明中,我绝对推荐使用 setuptools (又名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 指出)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM