简体   繁体   English

Python 模块安装问题

[英]Python Module Installation Problems

I'm having a ton of trouble installing modules.我在安装模块时遇到了很多麻烦。 At first I thought I had messed with my python installation on mac os x but I installed a virtual machine and ubuntu 11.04 and have similar troubles.起初我以为我在 mac os x 上安装了 python,但我安装了虚拟机和 ubuntu 11.04 并且有类似的麻烦。 Why are both os x and ubuntu failing with the same error?为什么 os x 和 ubuntu 都失败并出现相同的错误?

For example I can't install tkinter with it failing:例如,我无法安装 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

I encountered exactly the same problem when trying to install tkinter-pypy on Ubuntu 11.04.尝试在 Ubuntu 11.04 上安装 tkinter-pypy 时遇到了完全相同的问题。 The error message shows that it's looking for tcl.h file in /usr/include/tcl, but it's not there.错误消息显示它正在 /usr/include/tcl 中寻找 tcl.h 文件,但它不存在。 I have to install the dev version of the tcl library (I installed tcl8.4-dev).我必须安装 tcl 库的 dev 版本(我安装了 tcl8.4-dev)。

sudo apt-get install tcl8.4-dev

This installs the header files to /usr/include/tcl8.4.这会将 header 文件安装到 /usr/include/tcl8.4。 I then created a symlink /usr/include/tcl pointing to that.然后我创建了一个符号链接 /usr/include/tcl 指向它。 I also installed the dev version of the tk library (eg tk8.4-dev) which installed the tk.h header (needed too by tkinter-pypy) in the /usr/include/tcl directory.我还安装了 tk 库的开发版本(例如 tk8.4-dev),它在 /usr/include/tcl 目录中安装了 tk.h header(tkinter-pypy 也需要)。

After these steps, tkinter-pypy can be installed successfully.经过这些步骤,tkinter-pypy就可以安装成功了。

Not sure about the error, but Tkinter should be available with your Python install.不确定该错误,但 Tkinter 应该可用于您的 Python 安装。 Have you tried to import Tkinter .您是否尝试过import Tkinter On a related note I'd definitely recommend using setuptools (aka. easy_install ) or one of the other similar installation tools.在相关说明中,我绝对推荐使用 setuptools (又名easy_install )或其他类似的安装工具之一。

EDIT编辑

If Tkinter is still not available, then, on Linux, try locate lib-tk and adding it to your python path如果 Tkinter 仍然不可用,那么在 Linux 上,尝试locate lib-tk并将其添加到您的 python 路径

import sys; sys.path.append(PATH_TO_TK)

Then check out the Wiki to get the setup to stick: http://wiki.python.org/moin/TkInter然后查看 Wiki 以获取设置: http://wiki.python.org/moin/TkInter

Another EDIT另一个编辑

A simple work around might be to install IDLE, which depends on Tkinter (noted by the OP).一个简单的解决方法可能是安装 IDLE,这取决于 Tkinter(由 OP 指出)。

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

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