簡體   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