我已经在Ubuntu 12.04 x86_64上安装了pyqrcode => PyQRCode
通过运行make && sudo make install。

在成功进行make / make安装的最后,最后一行是:


  已安装
  /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

最佳答案

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'>

关于python - Python ImportError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11379382/

10-17 01:38