AlgerianPancake
AlgerianPancake

Reputation: 69

Trying to render a barcode image, but object is not callable?

I am trying to set up a code which creates tickets by generating images of barcodes, from a txt file, and pasting that on the ticket image.

import barcode
import time
from barcode.writer import ImageWriter
mylist = []
with open('/Users/Droid/Desktop/my_project/Tickets/Tnumfile.TXT', 'r') as f:
for line in f.readlines():    #Walks through each line
    code = barcode.get('code', line, writer=ImageWriter()) 
    filename = code.save(line.strip())        #Saves Line 'tnumfile' as filename
    mylist.insert(0,line.strip() + '.png')



time.sleep(2)
from PIL import Image

for item in mylist:

im1 = Image.open('/Users/Droid/Desktop/my_project/Ticket.png') 
im2 = Image.open('/Users/Droid/Desktop/my_project/Tickets' + item) 
area = (30, 1380, 553, 1660)                                       

im1.paste(im2, area)
im1.save('line' + item)

supposed to run through .txt file converting all the barcodes to images and copying them onto the ticket image template, instead keeps telling me:

  File "C:\Users\Droid\Desktop\my_project\Script.py", line 7, in <module>
    code = barcode.get('code', line, writer=ImageWriter())  
TypeError: 'NoneType' object is not callable

Upvotes: 5

Views: 4214

Answers (2)

Alexandre Crivellaro
Alexandre Crivellaro

Reputation: 893

Try this installation:

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

Upvotes: 0

Martijn Pieters
Martijn Pieters

Reputation: 1121584

The python-barcode project requires Pillow to be installed if you want to render barcodes to an image, otherwise it sets ImageWriter to None. See the barcode.writer source code for details (PIL is the name of the package that Pillow provides).

Run pip install Pillow to remedy this.

You can also tell pip to pull in dependencies by installing the python-barcode images extras:

pip install python-barcode[images]

Upvotes: 15

Related Questions