我已经安装了 pyqrcode => PyQRCode在 Ubuntu 12.04 x86_64 上。 通过运行 make && sudo make install。
在成功的 make/make install 结束时,最后一行是:
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
最佳答案
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 导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11379382/