如何在python3.7中生成条形码

2024-05-15 14:38:53 发布

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

我使用的是python3.7,为了生成条形码,我尝试使用“pip install pyBarcode”安装pyBarcode库。但它显示了以下错误:

找不到满足pyBarcode要求的版本(来自版本:) 找不到pyBarcode的匹配分发

现在,如何为python版本安装“pyBarcode”?在


Tags: installpip版本错误条形码pybarcode
3条回答

更新

这意味着它不支持Python3.7。 试试这个pip install python-barcode

运行此示例可帮助您理解:

import barcode
from barcode.writer import ImageWriter
from barcode import generate

print(barcode.PROVIDED_BARCODES)
EAN = barcode.get_barcode_class('ean13')
ean = EAN('5901234123457')
fullname = ean.save('ean13_barcode')
ean = EAN('5901234123457', writer=ImageWriter())

f = open('barcode.svg', 'wb')
ean.write(f)

name = generate('EAN13', '5901234123457', output='barcode_svg')
generate('EAN13', '5901234123457', writer=ImageWriter(), output='barcode')
import barcode
from barcode.writer import ImageWriter
from barcode import generate
def testEan():
    EAN = barcode.get_barcode_class('ean13')
    ean = EAN(u'5901234123457', writer=ImageWriter())
    fullname = ean.save('ean13_barcode')
    u'ean13_barcode.png'
    name = generate('EAN13', u'5901234123457', output='barcode_svg')
    print(name)
if __name__ == '__main__':
    testEan()

首先安装右库:

pip install python-barcode

然后编码:

^{pr2}$

此代码生成

enter image description here

相关问题 更多 >