OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How fix ghostscript error in datamatrix pyton code?

  • Thread starter Thread starter Valentin
  • Start date Start date
V

Valentin

Guest
I need to make a service that generates a datamatrix. I found an example on this site and am trying to use it. But when I launch I get an error. What is the problem, can anyone tell me? ghostscript was installed:

via https://gitlab.com/pdftools/python-ghostscript and via pip install ghostscript and how windows binary

ghostscript in PATH is present:

C:\Users\user>path PATH=C:\Program Files\gs\gs10.03.1\bin;

Code:
from treepoem import generate_barcode
from PIL import Image


def generate_and_print(gtin, serial_number, expiry_date, batch_number):
    # Generate datamatrix
    datamatrix = generate_barcode(
        barcode_type='gs1datamatrix',
        data=f"(01){gtin}(21){serial_number}(17){expiry_date}(10){batch_number}",
        options={"parsefnc": True, "format": "square", "version": "26x26"})

    # Resize datamatrix to desired size
    dm_size_px = (120, 120)
    datamatrix = datamatrix.resize(dm_size_px, Image.NEAREST)

    # Create white picture
    picture_size_px = (200, 200)
    picture = Image.new('L', picture_size_px, color='white')

    # Position the datamatrix
    barcode_position_px = (40, 40)
    picture.paste(datamatrix, barcode_position_px)

    # Save the image
    picture.save("datamatrix.png")


gtin = "01234567890128"
serial_number = "01234567891011"
expiry_date = "250731"
batch_number = "DATAMATRIXTEST"

generate_and_print(gtin, serial_number, expiry_date, batch_number)

And when I execute I get an error.

Code:
Traceback (most recent call last):
  File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 33, in <module>
    generate_and_print(gtin, serial_number, expiry_date, batch_number)
  File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 7, in generate_and_print
    datamatrix = generate_barcode(
                 ^^^^^^^^^^^^^^^^^
  File "C:\Users\user\.virtualenvs\pythonProject-dpBaQBJj\Lib\site-packages\treepoem\__init__.py", line 172, in generate_barcode
    _ghostscript_binary(),
    ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\.virtualenvs\pythonProject-dpBaQBJj\Lib\site-packages\treepoem\__init__.py", line 112, in _ghostscript_binary
    raise TreepoemError("Cannot determine path to ghostscript, is it installed?")
treepoem.TreepoemError: Cannot determine path to ghostscript, is it installed?

Process finished with exit code 1
<p>I need to make a service that generates a datamatrix. I found an example on this site and am trying to use it. But when I launch I get an error. What is the problem, can anyone tell me?
ghostscript was installed:</p>
<p>via <a href="https://gitlab.com/pdftools/python-ghostscript" rel="nofollow noreferrer">https://gitlab.com/pdftools/python-ghostscript</a>
and via
<code>pip install ghostscript</code>
and how windows binary</p>
<p>ghostscript in PATH is present:</p>
<p>C:\Users\user>path
PATH=C:\Program Files\gs\gs10.03.1\bin;</p>
<pre><code>from treepoem import generate_barcode
from PIL import Image


def generate_and_print(gtin, serial_number, expiry_date, batch_number):
# Generate datamatrix
datamatrix = generate_barcode(
barcode_type='gs1datamatrix',
data=f"(01){gtin}(21){serial_number}(17){expiry_date}(10){batch_number}",
options={"parsefnc": True, "format": "square", "version": "26x26"})

# Resize datamatrix to desired size
dm_size_px = (120, 120)
datamatrix = datamatrix.resize(dm_size_px, Image.NEAREST)

# Create white picture
picture_size_px = (200, 200)
picture = Image.new('L', picture_size_px, color='white')

# Position the datamatrix
barcode_position_px = (40, 40)
picture.paste(datamatrix, barcode_position_px)

# Save the image
picture.save("datamatrix.png")


gtin = "01234567890128"
serial_number = "01234567891011"
expiry_date = "250731"
batch_number = "DATAMATRIXTEST"

generate_and_print(gtin, serial_number, expiry_date, batch_number)
</code></pre>
<p>And when I execute I get an error.</p>
<pre><code>Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 33, in <module>
generate_and_print(gtin, serial_number, expiry_date, batch_number)
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 7, in generate_and_print
datamatrix = generate_barcode(
^^^^^^^^^^^^^^^^^
File "C:\Users\user\.virtualenvs\pythonProject-dpBaQBJj\Lib\site-packages\treepoem\__init__.py", line 172, in generate_barcode
_ghostscript_binary(),
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\.virtualenvs\pythonProject-dpBaQBJj\Lib\site-packages\treepoem\__init__.py", line 112, in _ghostscript_binary
raise TreepoemError("Cannot determine path to ghostscript, is it installed?")
treepoem.TreepoemError: Cannot determine path to ghostscript, is it installed?

Process finished with exit code 1

</code></pre>
 

Latest posts

Top