2011-07-10 247 views
2

我在安裝模塊時遇到了很多麻煩。起初我以爲我在mac os x上搞砸了我的python安裝,但是我安裝了一個虛擬機和ubuntu 11.04,並且有類似的麻煩。爲什麼os x和ubuntu都出現同樣的錯誤?Python模塊安裝問題

例如我不能用它未能安裝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 
+0

我以爲Tkinter是一個內置的軟件包。你有沒有試過導入它? – fncomp

+0

我很確定它也是。 – Blender

+0

我把我的評論作爲答案,我檢查了幾次安裝,並且它沒有任何行動可用。 – fncomp

回答

2

不知道的錯誤,但Tkinter的應該是可用你的Python安裝。你有沒有試過import Tkinter。在相關說明中,我肯定會推薦使用setuptools(aka。easy_install)或其他類似的安裝工具之一。

編輯

如果Tkinter的是還沒有上市,那麼,在Linux上,嘗試locate lib-tk並將其添加到你的Python路徑

import sys; sys.path.append(PATH_TO_TK)

然後檢查了維基來獲取設置堅持:http://wiki.python.org/moin/TkInter

另一編輯

一個簡單的解決方法可能是安裝IDLE,這取決於Tkinter(由OP指出)。

+0

與Ubuntu一起提供的軟件包對我來說並不算什麼。 Python 2.7.1+(r271:86832,2011年4月11日,18:05:24) [GCC 4.5.2] on linux2 輸入「help」,「copyright」,「credits」或「license」信息。 >>>進口Tkinter的 回溯(最近通話最後一個): 文件 「」,1號線,在 導入錯誤:沒有模塊名爲Tkinter的 – PFlans

+1

@PFM情況下,重要的嘗試'進口Tkinter' – fncomp

+0

>>>進口Tkinter的 回溯(最近呼叫最後): 文件「」,第1行,在 文件「/usr/lib/python2.7/lib-tk/Tkinter。py「,第42行,在 raise ImportError,str(msg)+',請安裝python-tk軟件包' ImportError:沒有名爲_tkinter的模塊,請安裝python-tk軟件包 – PFlans

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指向它。我還在/ usr/include/tcl目錄中安裝了tk庫的開發版本(例如tk8.4-dev),它安裝了tk.h頭文件(tkinter-pypy也需要)。

完成這些步驟後,可以成功安裝tkinter-pypy。

+0

感謝您的信息,讓我們來看看我是否能夠弄清楚如何在Windows中做到這一點(也許編輯setup.py中的庫位置到tcl源文件的位置我下載的結果是相同的,但我認爲你的tcl(8.4)很少出於da TE。我在tcl8.5下載的源代碼。 –