生成条形码时出现python错误

2024-04-28 11:01:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Windows中使用Python2.7和pyBarcode 0.7,并尝试使用以下示例代码(可在pyBarcode网页中找到)将条形码生成为png图像

>>> import barcode
>>> barcode.PROVIDED_BARCODES
[u'code39', u'ean', u'ean13', u'ean8', u'gs1', u'gtin', u'isbn', u'isbn10',
 u'isbn13', u'issn', u'jan', u'pzn', u'upc', u'upca']
>>> EAN = barcode.get_barcode_class('ean13')
>>> EAN
<class 'barcode.ean.EuropeanArticleNumber13'>
>>> ean = EAN(u'5901234123457')
>>> ean
<barcode.ean.EuropeanArticleNumber13 object at 0x00BE98F0>
# Example with PNG
>>> from barcode.writer import ImageWriter
>>> ean = EAN(u'5901234123457', writer=ImageWriter())
>>> fullname = ean.save('ean13_barcode')

最后一行生成以下错误:

^{pr2}$

我重新安装了Pillow(但在此之前我删除了pill);我下载了“Pillow-4.2.1-win32-py2_7.exe” 我还做了“pip安装枕头”。在

当我想逃跑的时候

import barcode

我得到了:

  File "barcode\codex.py", line 12, in <module>

    from barcode.base import Barcode

  File "barcode\base.py", line 9, in <module>

    from barcode.writer import SVGWriter

  File "barcode\writer.py", line 12, in <module>

    import Image, ImageDraw, ImageFont

  File "c:\python27\lib\site-packages\PIL\Image.py", line 27, in <module>

    from . import VERSION, PILLOW_VERSION, _plugins

ValueError: Attempted relative import in non-package

我该怎么办?在

谢谢


Tags: infrompyimportlineeanean13barcode