我正在使用Python 3.7,想要生成条形码,尝试使用pip install pyBarcode
命令安装pyBarcode库,但出现以下错误:
找不到满足pyBarcode要求的版本(来自版本:) 没有找到匹配的分发版。
现在,我该如何为我的Python版本安装pyBarcode
呢?
首先安装正确的库:
pip install python-barcode
那么代码是:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import barcode
from barcode.writer import ImageWriter
def testEan():
EAN = barcode.get_barcode_class('ean13')
ean = EAN(u'123456789011', writer=ImageWriter())
fullname = ean.save('my_ean13_barcode')
if __name__ == '__main__':
testEan()
这意味着它不支持Python 3.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')
pip install treepoem
# or
python -m pip install treepoem
import treepoem
image = treepoem.generate_barcode(
barcode_type="code128", # One of the BWIPP supported codes.
# barcode_type="qrcode",
# One of the BWIPP supported codes.
# barcode_type="interleaved2of5", # One of the BWIPP supported codes.
# barcode_type="code128", # One of the BWIPP supported codes.
# # barcode_type="isbn", # One of the BWIPP supported codes.
# # data="978-3-16-148410-0",
# barcode_type="code128", # One of the BWIPP supported codes.
# barcode_type="micropdf417", # One of the BWIPP supported codes.
# barcode_type="ean13", # One of the BWIPP supported codes.
data="Your String -978316148fsd4100",
)
image.convert("1").save("output_qrcode_or_barcode.png")
安装以下软件包:
pip install python-barcode
pip install Pillow
然后尝试此代码片段:
from barcode import EAN13
from barcode.writer import ImageWriter
with open('sample.png', 'wb') as f:
e = EAN13('123412341234', writer=ImageWriter())
e.write(f)
e.g:
输入:123412341234
输出:1234123412344
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()
import barcode
hr = barcode.get_barcode_class('ean13')
Hr = hr('1234567891012')
qr = Hr.save('123')