2012-07-07 42 views
1

我在Ubuntu 12.04 x86_64上安裝了pyqrcode =>PyQRCode。 通過運行make & & sudo make install。Python ImportError

在隨後結束的成功品牌/ make安裝,最後一行是:

Installed /usr/local/lib/python2.7/dist-packages/qrcode-0.2.1-py2.7-linux-x86_64.egg

但是,當我嘗試導入的QRCode我得到這個錯誤:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "qrcode/__init__.py", line 6, in <module> 
    from qrcode import _qrcode 
ImportError: cannot import name _qrcode 
+0

我也嘗試過使用pip,它說qrcode已經安裝(從源安裝後嘗試) – michael 2012-07-07 23:11:55

回答

2

sudo pip install qrcode工作就好了爲了我。

我的猜測是在編譯之後,你從源目錄啓動了Python,因此它在本地qrcode目錄中查找 - 即pyqrcode-0.2.1/qrcode,而不是在通常的Python路徑中查找。嘗試從另一個目錄運行它。具體來說:

~/sys/pyqrcode-0.2.1$ python 
Python 2.7.3 (default, Apr 20 2012, 22:44:07) 
[GCC 4.6.3] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import qrcode 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "qrcode/__init__.py", line 6, in <module> 
    from qrcode import _qrcode 
ImportError: cannot import name _qrcode 
>>> 
~/sys/pyqrcode-0.2.1$ cd ~ 
~$ python 
Python 2.7.3 (default, Apr 20 2012, 22:44:07) 
[GCC 4.6.3] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import qrcode 
>>> qrcode 
<module 'qrcode' from '/usr/local/lib/python2.7/dist-packages/qrcode/__init__.pyc'> 
+0

hmm。幾乎解決了我的問題!如果我從根運行python,我會得到更多。它抱怨:_qrcode._setExceptionTypes(JavaError,InvalidArgsError)AttributeError:'模塊'對象沒有屬性'_setExceptionTypes – michael 2012-07-07 23:27:02

+0

源版本似乎有點奇怪。嘗試刪除你安裝的那個,然後再次嘗試一下pip,看起來對我來說無論如何(與你使用的12.04 x86_64相同)。[IOW,我認爲這是來自ImportError的一個獨立問題。這是一個路徑搜索順序問題;這個新的是一個更基本的問題。] – DSM 2012-07-07 23:33:27

+0

這似乎工作。謝謝。 – michael 2012-07-07 23:37:18