2010-10-24 101 views
12

我已經在Ubuntu Maverick Meerkat(10.10)上從Python 2.6升級到Python 2.7,我無法導入PyQt4。Python 2.7無法導入PyQt4

[email protected]:~$ python2.7 
Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55) 
[GCC 4.4.5] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import PyQt4 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named PyQt4 

我從Ubuntu存儲庫安裝了Python 2.7(python2.7)和PyQt4(python-qt4)。我安裝了PyQt,但是我最近安裝了Python 2.7。

如果我嘗試使用Python 2.6(因爲它與Ubuntu一起發佈,命令只是python),它可以很好地工作。關注:

[email protected]:~$ python 
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
[GCC 4.4.5] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import PyQt4 

我知道是什麼問題:在PyQt4的模塊是由Python 2.6中訪問,但不是2.7。我的問題是,我如何讓Python 2.7找到PyQt4模塊?幫幫我!

注意:對不起,如果這屬於超級用戶,我只是編程,當我遇到這個問題。

回答

3

在Ubuntu系統,你可以通過安裝apt-get的

apt-get install python-qt4 
+0

將此標記爲答案,因爲即使在最舊的支持Ubuntu發佈(12.04 LTS atm),'python'包現在是2.7版本,謝謝! – 2016-08-04 13:51:19

1

您應該在Python 2.7環境中安裝PyQt4。要做到這一點來看

easy_install2.7 PyQt4 

如果easy_install的未安裝則需要先下載並沒有使用setup.py不能使用PIP或easy_install的安裝運行

python2.7 setup.py install 
+1

原諒我,但我想要做一個備註,爲什麼不點子?你沒有聽說過,「easy_install已經死了很長時間了嗎?」) – mouad 2010-10-24 22:48:36

+0

是的,你是對的。 :)我只是習慣easy_install – EMP 2010-10-24 23:43:06

+2

這沒有奏效。當我運行「easy_install-2.7 PyQt4」時,它只是說「閱讀http://pypi.python.org/simple/PyQt4/ 找不到'PyQt4'的索引頁(可能是拼寫錯誤?) 掃描所有軟件包的索引(這可能需要一段時間) 閱讀http://pypi.python.org/simple/ 沒有找到PyQt4的本地包或下載鏈接 錯誤:無法找到Requirement.parse('PyQt4')的合適分佈: (如何使用pip? – 2010-10-25 01:02:52

1

請首先安裝SIP模塊,這是Python和C/C++庫工具,和PyQt4的LIB

4

OSX 10.8 0.2測試:

sudo pip install SIP 

得到IO錯誤:[錯誤2]沒有這樣的文件或目錄: '/tmp/pip-build/SIP/setup.py'

它的確定,則:從

cd /tmp/pip-build/SIP 
sudo python configure.py 
make 
sudo make install 

下載PyQt的:http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.9.6/PyQt-mac-gpl-4.9.6.tar.gz

解壓。

cd PyQt-mac-gpl-4.9.6 
sudo python configure.py 
make 

這將需要一段時間,之後再作出:

sudo make install  

享受吧:)

+0

運行make給我'錯誤:無法打開輸出文件'main.o':'打開輸出文件main.o時出錯'''' – Lango 2013-07-30 11:11:30