解決centos中"ImportError: No module named _tkinter"相關問題

來源:互聯網
上載者:User

解決centos中"ImportError: No module named _tkinter"相關問題
今天想要用Metasploit的時候出現了"ImportError: No module named _tkinter"的錯誤,_tkinter是被Tkinter模組引用的,因為對Tkinter不太熟悉所以也不知道為什麼會有這個錯誤。
我本身是在centos中,而且系統中存在不同的帳號分別使用了不同版本的Python,所以我先在root帳號下試了一下import Tkinter是OK的,接著用命令import _tkinter;_tkinter;列印了一下_tkinter的檔案路徑,發現是在”/usr/lib64/python2.7/lib-dynload/”目錄下面,而且是so檔案。
首先我想到直接把root下面的_tkinter.so直接拷貝到xxuser帳號的Python lib-dynload中,但是我發現會有undefined symbol: PyUnicodeUCS4_AsUTF8String的錯誤,也就是因為root、xxuser兩者之間的Python編譯參數不同導致的,看來這種方式是不可行了。
接著網上找了一圈沒有發現能直接安裝_tkinter的命令,後來我想到這個_tkinter.so是不是在編譯Python的時候產生的呢?所以我下載了一個跟xxuser當前Python版本一致的Python源碼,編譯的時候選擇--enable-unicode=ucs2,重新./configure、make以後在build/lib.linux-x86_64-2.7目錄下面確實產生了_tkinter.so,然後把_tkinter.so拷貝到xxuser帳號的Python lib-dynload中,運行import Tkinter就OK了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.