python INFO: Can't locate Tcl/Tk libs and/or headers


今天在學python的時候使用Tkinter包的時候出現以下問題:

 File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>

    import _tkinter # If this fails your Python may not be configured for Tk

ImportError: No module named _tkinter

 

然后就給python重新安裝了一遍 結果發現:

running install
running build
running build_ext
INFO: Can't locate Tcl/Tk libs and/or headers

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _curses            _curses_panel   
_sqlite3           _tkinter           bsddb185        
dbm                dl                 gdbm            
imageop            sunaudiodev                        
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

 

是少了Tcl/Tk,於是就直接 apt-get install tcl     apt-get install tk 安裝了tcl和tk庫 ,然后又執行  python setup.py install  安裝  python:

結果還是不行,還是提示Can't locate Tcl/Tk libs and/or headers 郁悶呀;

然后就又百度了下 找到一篇博客:http://www.linuxdiyf.com/viewarticle.php?id=55587 講的比較詳細:

原來setup.py 安裝的時候要尋找tcl.h和tk.h兩個頭文件,但是我用find / -name tcl.h在整個linux范圍內都沒有找到這個頭文件。

再仔細看python.org/topics/tkinter/給出的指導:

You may have to install Tcl and Tk(when using RPM, install the –devel RPM as well) and /or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning “make” should build the _tkinter extension.

所以我要安裝tcl-devel(我的系統是debian安裝的是tcl-dev)和tk-devel(我的系統是debian安裝的是tk-dev)才能有頭文件,安裝tcl/tk,只是把靜態或者動態庫考到lib目錄下,只有tcl-devel(tc-dev),tk-devel(tk-dev)才會把頭文件放到/usr/include里邊,而_tkinter要編譯必須找到這些頭文件。

然后我就執行了 

apt-get install tcl-dev    

apt-get install tk-dev 

安裝完這兩個包后問題就解決了。。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM